
; Asar directives
hirom
org $C30000
table ff6_bank_c3j.tbl,rtl
incsrc ff6_bank_c3j_defs.asm


; Entry points
C30000:  JMP C3001B      ; Invoke desired field menu
         JMP C3AC70      ; Decode joypads for battle
         JMP C3AC4F      ; Initialize joypad data
         JMP C3ACA5      ; Decode joypads for field
         JMP C31433      ; Advance play time
         JMP C31569      ; Load save data on defeat
         JMP C3D48B      ; Show an ending cinematic
         JMP C39EC1      ; Optimize member's gear
         JMP C3E4E4      ; Load map for final land

; Invoke requested field menu
C3001B:  REP #$10        ; 16-bit X, Y
         SEP #$20        ; 8-bit A
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         LDA $0200       ; Menu to open
         CMP #$02        ; Load menu?
         BNE C3003F      ; Branch if not
         JSR C3782F      ; Reset game data
C3003F:  JSR C300F8      ; Load GFX, colors
         JSR C300DD      ; Handle menu
         JSL C3AC4F      ; Get joypad config
         JSR C3D4E5      ; Disable pad, etc.

; Fork: Leaving Load menu
C30057:  LDA $0200       ; Menu closed
         CMP #$02        ; Load menu?
         BNE C3006F      ; Branch if not
         LDA $0205       ; Start new game?
         BPL C3006F      ; Branch if so
         LDA $1D4E       ; Game options
         AND #$20        ; Stereo sound?
         BEQ C3006F      ; Branch if so
         LDA #$FF        ; Mode: Mono
         JSR C33F46      ; Adjust volume

; Fork: Rename Card
C3006F:  LDA $0200       ; In main menu?
         BNE C300BF      ; Return if not
         LDA $0205       ; Rename request?
         BPL C300BF      ; Return if not
         CMP #$FE        ; Rename actor?
         BNE C3009E      ; SwdTech if not
         LDA $0201       ; Area permissions
         PHA             ; Preserve them
         LDY $0206       ; Actor's address
         STY $0201       ; Set as target's
         LDA #$01        ; Menu number
         BRA C300AF      ; Call naming menu

; Fork: SwdTech renaming
C3009E:  LDA $0201       ; Area permissions
         PHA             ; Preserve them
         LDA $0206       ; Chosen SwdTech
         STA $0201       ; Set as target
         LDA #$06        ; SwdTech renaming
C300AF:  STA $0200       ; Set menu number
         JSL C30000      ; Call naming menu
         PLA             ; Area permissions
         STA $0201       ; Restore them
         STZ $0200       ; Menu: Main
         JMP C3001B      ; Open main menu
C300BF:  RTL

; Reroute interrupt vectors
C300C0:  LDA #$5C        ; JML opcode
         STA $1500       ; Put by NMI loc
         STA $1504       ; Put by IRQ loc
         LDX #C313F2     ; C3/13F2
         STX $1501       ; Set NMI LBs
         LDX #C31432     ; C3/1432
         STX $1505       ; Set IRQ LBs
         LDA #$C3        ; Bank: C3
         STA $1503       ; Set NMI HB
         STA $1507       ; Set IRQ HB
         RTS

; Access requested field menu
C300DD:  TDC             ; Clear A
         LDA $0200       ; Menu to open
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C300E6,X)  ; Invoke menu

; Jump table for the above
C300E6:  dw C3011A       ; Main menu
         dw C301B3       ; Actor naming
         dw C3016F       ; Load menu
         dw C30121       ; Shop
         dw C3012B       ; Lineup
         dw C30000       ; Bogus...
         dw C30149       ; SwdTech naming
         dw C30152       ; Colosseum
         dw C30166       ; Final battle lineup

; Load menu graphics and colors; initialize general variables
C300F8:  JSR C3706C      ; Reset variables
         JSR C37087      ; Get party info
;        JSR C3711B      ; No use...
         JSL $D4CD48     ; Init registers
         JSL C3AC4F      ; Init joypad data
         TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         JSR C37170      ; Queue Win1 HDMA
         JSR C3117F      ; Reset OAM, queue
         JSR C3721B      ; Load nonskin GFX
         JMP C33B5B      ; Load skin visuals

; Clear cursor position restored from Lineup's Status menu...
C30138:; TDC             ; Clear A
       ; TAY             ; Clear Y
       ; STY $8E         ; Clear position
       ; RTS

; Invoke main menu
C3011A:  LDA #$04        ; C3/1AF0
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke shop menu
C30121:  JSR C340B9      ; Apply user font
         LDA #$24        ; C3/C3C0
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Lineup menu
C3012B:  JSR C340B9      ; Apply user font
;        JSR C30138      ; Clear saved cursor
         LDA #$2C        ; C3/787B
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke SwdTech naming menu
C30149:  JSR C340B9      ; Apply user font
         LDA #$3F        ; C3/BE00
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Colosseum menu
C30152:  JSR C340B9      ; Apply user font
;        STZ $79         ; Never read...
;        STZ $7A         ; Never read...
;        STZ $7B         ; Never read...
         LDA #$71        ; C3/B619
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke final battle lineup
C30166:  JSR C340B9      ; Apply user font
         LDA #$73        ; C3/B368
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Invoke Load menu
C3016F:  LDA $307FF1     ; RNG index in SRAM
         INC A           ; RNG index +1
         STA $307FF1     ; Save changes
         JSL C3AC4F      ; Init joypad data
         JSR C377B7      ; Test SRAM markers
         BCC C3019F      ; Abort if invalid
         LDA #$01        ; Song: The Prelude
         STA $1301       ; Set I/O port 1
         LDA #$10        ; APU command
         STA $1300       ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $1302       ; Set I/O port 2
         JSL $C50004     ; Play song
         LDA #$FF        ; New game: No
         STA $0205       ; Preset exit mode
         LDA #$20        ; C3/1D69
         STA $26         ; Next: Init menu
         BRA C301BA      ; Enter menu loop

; Fork: Force new game
C3019F:  JSR C32ABC      ; Reset play time
         LDA #$01        ; Save slot: 1
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         JSR C3F1A3      ; Next: Exit menu
         STZ $0205       ; Set new game mode
         BRA C301BA      ; Enter menu loop

; Invoke actor naming menu
C301B3:  JSR C340B9      ; Apply user font
         LDA #$5D        ; C3/6B5E
         STA $26         ; Next: Init menu

; Main loop for field menus
C301BA:  JSR C3147D      ; Refresh screen
C301BD:  TDC             ; Clear A
         LDA $26         ; Menu command
         CMP #$FF        ; Exit to map?
         BEQ C301D8      ; Branch if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C301DB,X)  ; Handle menu cmd
         JSR C3121B      ; Handle anim queue
         JSR C313B8      ; Update screen/pad
         JSR C302DB      ; Check event timer
         BRA C301BD      ; Loop
C301D8:  STZ $43         ; Disable HDMA
         RTS

; Jump table for the above
C301DB:  dw C31DD7       ; 00: Fade out screen
         dw C31DE4       ; 01: Fade in screen
         dw C31DF1       ; 02: Wait while menu fades in or out
         dw C31DFA       ; 03: Exit main menu's portrait area
         dw C31AF0       ; 04: Initialize main menu
         dw C31E0A       ; 05: Sustain main menu
         dw C31E4E       ; 06: Target one actor in main menu
         dw C31B3C       ; 07: Initialize Item menu
         dw C31F5D       ; 08: Handle Item menu choice 1
         dw C31BC1       ; 09: Initialize Skills menu
         dw C3205A       ; 0A: Sustain Skills menu
         dw C31CAC       ; 0B: Initialize Status menu
         dw C32255       ; 0C: Sustain Status menu
         dw C31CE3       ; 0D: Initialize Config menu
         dw C32325       ; 0E: Sustain Config menu
         dw C3247F       ; 0F: Handle Order menu choice 1
         dw C324C6       ; 10: Handle Order menu choice 2
         dw C3251C       ; 11: Switch members in Order menu
         dw C325AA       ; 12: Wait while member changes row
         dw C31D06       ; 13: Initialize Save menu
         dw C325B3       ; 14: Sustain Save menu
         dw C31D49       ; 15: Initialize save confirmation
         dw C32610       ; 16: Sustain save confirmation
         dw C32667       ; 17: Handle Item menu options
         dw C327B4       ; 18: Sustain rare item menu
         dw C327EC       ; 19: Handle Item menu choice 2
         dw C32855       ; 1A: Sustain Magic menu
         dw C328FD       ; 1B: Sustain Lore menu
         dw C3291D       ; 1C: Sustain Dance menu
         dw C3292D       ; 1D: Sustain Rage menu
         dw C32946       ; 1E: Handle esper selection
         dw C30000       ; 1F: Unused...
         dw C31D69       ; 20: Initialize Load menu
         dw C32A5D       ; 21: Sustain Load menu
         dw C31DB7       ; 22: Initialize load confirmation
         dw C32AC5       ; 23: Sustain load confirmation
         dw C3C3C0       ; 24: Initialize shop menu
         dw C3C3F2       ; 25: Sustain main shop menu
         dw C3C414       ; 26: Handle buy item list
         dw C3C45C       ; 27: Handle buy order menu
         dw C3C565       ; 28: Return to Buy menu after delay
         dw C3C56D       ; 29: Handle sell item list
         dw C3C5CD       ; 2A: Handle sell order menu
         dw C3C6A9       ; 2B: Return to Sell menu after delay
         dw C3787B       ; 2C: Initialize Lineup menu
         dw C378FC       ; 2D: Handle Lineup menu choice 1
         dw C379A0       ; 2E: Handle Lineup menu choice 2
         dw C30000       ; 2F: Unused...
         dw C30000       ; 30: Unused...
         dw C30000       ; 31: Unused...
         dw C30000       ; 32: Unused...
         dw C329E1       ; 33: Sustain Blitz menu
         dw C329AD       ; 34: Wait while showing who holds esper
         dw C31C1E       ; 35: Initialize Equip menu
         dw C39E10       ; 36: Handle Equip menu options
         dw C31F1B       ; 37: Handle multitargeting in main menu
         dw C31C98       ; 38: Initialize party gear overview
         dw C329D0       ; 39: Sustain party gear overview
         dw C32B00       ; 3A: Initialize spell usage menu
         dw C32B49       ; 3B: Handle single-target spell
         dw C32DB7       ; 3C: Return to Magic menu
         dw C32E13       ; 3D: Handle multitarget spell
         dw C329F8       ; 3E: Sustain SwdTech menu
         dw C3BE00       ; 3F: Initialize SwdTech naming menu
         dw C3BE37       ; 40: Handle SwdTech naming choice 1
         dw C3BE7A       ; 41: Handle SwdTech naming choice 2
         dw C36966       ; 42: Initialize Lineup's Status menu
         dw C36988       ; 43: Sustain Lineup's Status menu
         dw C30000       ; 44: Unused...
         dw C30000       ; 45: Unused...
         dw C30000       ; 46: Unused...
         dw C343A3       ; 47: Initialize Cmd.Set menu
         dw C343C0       ; 48: Handle Cmd.Set menu member selection
         dw C3478E       ; 49: Initialize Button Settings menu
         dw C347AB       ; 4A: Sustain Button Settings menu
         dw C347E2       ; 4B: Initialize Controller menu
         dw C347FF       ; 4C: Sustain Controller menu
         dw C35F23       ; 4D: Sustain esper data menu
         dw C3BEEF       ; 4E: Scroll to SwdTech naming page 2
         dw C3BF17       ; 4F: Scroll to SwdTech naming page 1
         dw C33AD4       ; 50: Scroll to Config page 2
         dw C33AF5       ; 51: Scroll to Config page 1
         dw C31A73       ; 52: Queue fade-in for save menu
         dw C31A64       ; 53: Queue fade-out for save menu
         dw C31A82       ; 54: Wait while save menu fades in or out
         dw C3A073       ; 55: Handle selection of gear slot to fill
         dw C3A0BE       ; 56: Handle manual gear removal
         dw C3A0FE       ; 57: Handle gear browsing
         dw C3A659       ; 58: Initialize Relic menu
         dw C3A6C6       ; 59: Handle Relic menu options
         dw C3A80B       ; 5A: Handle selection of relic slot to fill
         dw C3A8A5       ; 5B: Handle relic browsing
         dw C3A918       ; 5C: Handle relic removal
         dw C36B5E       ; 5D: Initialize actor naming menu
         dw C39170       ; 5E: Sustain shifted gear data menu
         dw C36BA5       ; 5F: Sustain actor naming menu
         dw C36C4A       ; 60: Scroll to actor naming page 2
         dw C36C71       ; 61: Scroll to actor naming page 1
         dw C34419       ; 62: Handle Cmd.Set menu command choice 1
         dw C34457       ; 63: Handle Cmd.Set menu command choice 2
         dw C3910D       ; 64: Sustain non-shifted gear data menu
         dw C337AF       ; 65: Shift screen
         dw C38193       ; 66: Queue fade-in for Lineup menu
         dw C38184       ; 67: Queue fade-out for Lineup menu
         dw C381A2       ; 68: Wait while Lineup menu fades in or out
         dw C3821B       ; 69: Erase warning in Lineup menu after delay
         dw C369F0       ; 6A: Sustain shifted Status menu
         dw C30000       ; 6B: Unused...
         dw C3A7BF       ; 6C: Handle delayed fade-out for Reequip
         dw C31C80       ; 6D: Open Equip menu after optimizing gear
         dw C31C8C       ; 6E: Open Equip menu after removing all gear
         dw C3920E       ; 6F: Initialize item usage menu
         dw C39220       ; 70: Sustain item usage menu
         dw C3B619       ; 71: Initialize Colosseum item menu
         dw C3B64B       ; 72: Sustain Colosseum item menu
         dw C3B368       ; 73: Initialize final battle lineup
         dw C3B395       ; 74: Sustain final battle lineup
         dw C3B724       ; 75: Initialize Colosseum matchup menu
         dw C3B77C       ; 76: Sustain Colosseum matchup menu
         dw C31B9B       ; 77: Return from item usage menu
         dw C30000       ; 78: Unused...
         dw C3A68B       ; 79: Swap actor in Relic menu, retain Equip mode
         dw C3A699       ; 7A: Swap actor in Relic menu, retain Remove mode
         dw C30000       ; 7B: Unused...
         dw C30000       ; 7C: Unused...
         dw C378C5       ; 7D: Return to Lineup menu from Status menu
         dw C31C4B       ; 7E: Swap actor in Equip menu, retain Equip mode
         dw C31C59       ; 7F: Swap actor in Equip menu, retain Remove mode

; Set to exit menu if event countdown timer expired
C302DB:  LDA $B4         ; Already handled?
         BNE C302F8      ; Exit if so
         LDA $1188       ; Timer 0 flags
         BIT #$20        ; Abort if expired?
         BEQ C302F8      ; Exit if not
         LDY $1189       ; Timer expired?
         BNE C302F8      ; Exit if not
         JSR fdexit      ; Queue menu exit
         LDA #$05        ; Origin: Timer
         STA $0205       ; Set exit reason
         STA $B4         ; Disable this fn
C302F8:  RTS

; Draw text string without diacritics
C302F9:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
C302FD:  STA $E9         ; Set src HB
         STY $E7         ; Set src LBs
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set dst LBs
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDY #$0002      ; Src index
         LDX $00         ; Dst index: 0
C30312:  LDA [$E7],Y     ; Text character
         BEQ C302F8      ; Exit if <end>
         PHY             ; Save src index
         TXY             ; Dst index
         STA [$EB],Y     ; Add char to map
         INX             ; Dst index +1
         TXY             ; Move it to Y
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; Dst index +1
         PLY             ; Src index
         INY             ; Src index +1
         BRA C30312      ; Load next char

; Draw text string with diacritics but without Roman characters
C30326:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
C3032A:  STA $E9         ; Set src HB
         STY $E7         ; Set src LBs
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set dst LBs
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDY #$0002      ; Src index
         LDX $00         ; Dst index: 0

; Fork: Load current character
C3033F:  LDA [$E7],Y     ; Text character
         STA $E0         ; Memorize it
         BEQ C302F8      ; Exit if <end>

; Fork: Handle line break (unused?)
C30345:  CMP #$01        ; Line break?
         BNE C3035A      ; Branch if not
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Tilemap ptr
         ADC #$0080      ; Go 2 rows down
         STA $EB         ; Save changes
         LDX $00         ; Dst index: 0
         SEP #$20        ; 8-bit A
         INY             ; Src index +1
         BRA C3033F      ; Load next char

; Fork: Character without diacritic
C3035A:  PHY             ; Save src index
         CMP #$53        ; Normal char?
         BCC C30365      ; Branch if not
         LDA #$FF        ; Space char
         STA $E1         ; Set diacritic
         BRA C30385      ; Update tilemap

; Fork: Character with handakuten
C30365:  CMP #$49        ; Bogus char?
         BCC C30376      ; Branch if not
         LDA.B #!hnda    ; Mark: [°]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$17        ; Get true one
         STA $E0         ; Save changes
         BRA C30385      ; Update tilemap

; Fork: Character with dakuten
C30376:  CMP #$20        ; Roman range?
         BCC C30385      ; Branch if not
         LDA.B #!daku    ; Mark: ["]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$40        ; Get true one
         STA $E0         ; Save changes

; Fork: Add character to tilemap
C30385:  TXY             ; Base dst index
         LDA $E1         ; Diacritic
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         REP #$21        ; 16-bit A; C-
         TXA             ; Base RAM index
         ADC #$0040      ; Go 1 row down
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $E0         ; Base character
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; Dst index +1
         INX             ; Dst index +1
         PLY             ; Src index
         INY             ; Src index +1
         BRA C3033F      ; Load next char

; Load and adjust window tile numbers, define attributes
C303A9:  STY $E7         ; Save attributes
         LDX #$0036      ; Tile index
C303AF:  REP #$21        ; 16-bit A; C-
         LDA.L C304D1,X  ; Tile number
         ADC $E7         ; Add attributes
         STA $7E9F19,X   ; Save in RAM
         DEX             ; Index -1
         DEX             ; Index -1
         BPL C303AF      ; Loop till < 0
         SEP #$20        ; 8-bit A
         RTS

; Prepare to and draw a menu window
C303C4:  LDA #$C3        ; Bank: C3
C303C6:  STA $E9         ; Set src HB
C303C8:  STX $E7         ; Set src LBs
         LDY #$0002      ; Src index
         LDA [$E7],Y     ; Inner width
         STA $EF         ; Memorize it
         STZ $F0         ; Clear HB
         INY             ; Index +1
         LDA [$E7],Y     ; Inner height
         STA $F1         ; Memorize it
         STZ $F2         ; Clear HB
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         REP #$20        ; 16-bit A
         LDA [$E7]       ; Tilemap ptr
         STA $EB         ; Set position
         JSR C303F8      ; Draw window
         SEP #$20        ; 8-bit A
         RTS

; Draw a menu window
C303F8:  JSR C30426      ; Draw top row
         LDX $00         ; Inner row: 1st
         LDY #$0040      ; Skipped rows: 1
         STY $F3         ; Init map index
C30402:  PHX             ; Save row number
         TXA             ; Move it to A
         AND #$0003      ; Get pattern row
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C3041E,X)  ; Draw inner row
         LDA $F3         ; Tilemap index
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $F3         ; Save changes
         TAY             ; Index it
         PLX             ; Row number
         INX             ; Row number +1
         CPX $F1         ; At last row?
         BNE C30402      ; Loop if not
         BRA C3043E      ; Draw last row

; Jump table for the above
C3041E:  dw C30454       ; Pattern row 1 of 4
         dw C3045E       ; Pattern row 2 of 4
         dw C3046B       ; Pattern row 3 of 4
         dw C30478       ; Pattern row 4 of 4

; Draw window's upper row
C30426:  LDY $00         ; Map index: 0
         JSR C3048B      ; Define pattern
         LDA $7E9F49     ; NW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4B     ; NE corner tile
         STA $E5         ; Set final tile
         LDX #$0020      ; Base tile index
         BRA C304AB      ; Draw top row

; Draw window's lower row
C3043E:  JSR C3048B      ; Define pattern
         LDA $7E9F4D     ; SW corner tile
         STA $E3         ; Set first tile
         LDA $7E9F4F     ; SE corner tile
         STA $E5         ; Set final tile
         LDX #$0024      ; Base tile index
         BRA C304AB      ; Draw bottom row

; Draw inner window row, pattern part 1 of 4
C30454:  JSR C30485      ; Define pattern
         JSR C30491      ; Get side tiles
         LDX $00         ; Base tile index
         BRA C304AB      ; Draw inner row

; Draw inner window row, pattern part 2 of 4
C3045E:  JSR C30485      ; Define pattern
         JSR C3049E      ; Get side tiles
         LDX #$0008      ; Base tile index
         BRA C304AB      ; Draw inner row

; Draw inner window row, pattern part 3 of 4
C3046B:  JSR C30485      ; Define pattern
         JSR C30491      ; Get side tiles
         LDX #$0010      ; Base tile index
         STX $E0         ; Memorize it
         BRA C304AB      ; Draw inner row

; Draw inner window row, pattern part 4 of 4
C30478:  JSR C30485      ; Define pattern
         JSR C3049E      ; Get side tiles
         LDX #$0018      ; Base tile index
;        BRA C304AB      ; Draw inner row

; Draw a row of window tiles
C304AB:  STX $E0         ; Set base index
         LDX $00         ; Inner col: 1st
         LDA $E3         ; Leftmost tile
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         INY             ; Map index +1
C304B3:  PHX             ; Save column
         TXA             ; Move it to A
         AND $F5         ; Stay in pattern
         ASL A           ; Double it
;        CLC             ; ...
         ADC $E0         ; Add base index
         TAX             ; Index sum
         LDA $7E9F19,X   ; Inner tile
         PLX             ; Column number
         CPX $EF         ; At last one?
         BEQ C304CC      ; Branch if so
         STA [$EB],Y     ; Add tile to map
         INY             ; Map index +1
         INY             ; Map index +1
         INX             ; Column +1
         BRA C304B3      ; Do next tile
C304CC:  LDA $E5         ; Rightmost tile
         STA [$EB],Y     ; Add to tilemap
         RTS

; Set pattern width for inner window tiles
C30485:  LDX #$0003      ; Tiles: 4
         STX $F5         ; Set pattern width
         RTS

; Set pattern width for top or bottom window border
C3048B:  LDX #$0001      ; Tiles: 2
         STX $F5         ; Set pattern width
         RTS

; Get window side tiles for odd-numbered pattern row
C30491:  LDA $7E9F41     ; Left border A
         STA $E3         ; Set first tile
         LDA $7E9F43     ; Right border A
         STA $E5         ; Set final tile
         RTS

; Get window side tiles for even-numbered pattern row
C3049E:  LDA $7E9F45     ; Left border B
         STA $E3         ; Set first tile
         LDA $7E9F47     ; Right border B
         STA $E5         ; Set final tile
         RTS

; Window tile numbers
C304D1:  dw $0180        ; Inner part 1,1
         dw $0181        ; Inner part 1,2
         dw $0182        ; Inner part 1,3
         dw $0183        ; Inner part 1,4
         dw $0184        ; Inner part 2,1
         dw $0185        ; Inner part 2,2
         dw $0186        ; Inner part 2,3
         dw $0187        ; Inner part 2,4
         dw $0188        ; Inner part 3,1
         dw $0189        ; Inner part 3,2
         dw $018A        ; Inner part 3,3
         dw $018B        ; Inner part 3,4
         dw $018C        ; Inner part 4,1
         dw $018D        ; Inner part 4,2
         dw $018E        ; Inner part 4,3
         dw $018F        ; Inner part 4,4
         dw $0191        ; Upper border A
         dw $0192        ; Upper border B
         dw $0199        ; Lower border A
         dw $019A        ; Lower border B
         dw $0194        ; Left border A
         dw $0195        ; Right border A
         dw $0196        ; Left border B
         dw $0197        ; Right border B
         dw $0190        ; NW corner
         dw $0193        ; NE corner
         dw $0198        ; SW corner
         dw $019B        ; SE corner

; Draw 3 digits (16-bit number)
C30509:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0002      ; Skipped: 2
         BRA C3054A      ; Draw text

; Draw 4 digits
C30513:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C3054A      ; Draw text

; Draw 5 digits
C3051D:  LDY #$0005      ; Digits: 5
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C3054A      ; Draw text

; Draw 8 digits
C30526:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
         BRA C3054A      ; Draw text

; Draw 7 digits
C3052F:  LDY #$0008      ; Digits: 8
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C3054A      ; Draw text

; Draw 2 digits
C30539:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY #$0001      ; Skipped: 1
         BRA C3054A      ; Draw text

; Draw 3 digits (8-bit number)
C30543:  LDY #$0003      ; Digits: 3
         STY $E0         ; Set counter
         LDY $00         ; Skipped: 0
C3054A:  STX $EB         ; Set dst LBs
         SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         TYX             ; Digit index
         LDY $00         ; Map index: 0
C30553:  LDA $F7,X       ; Digit char
         STA [$EB],Y     ; Add to tilemap
         INY             ; Map index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INY             ; Map index +1
         INX             ; Digit index +1
         CPX $E0         ; More digits?
         BNE C30553      ; Loop if so
         RTS

; Convert 8-bit number into text, blank leading zeroes
C30563:  JSR C3057C      ; Turn into text
         LDY #$0002      ; Digits: 2
         BRA C305E_      ; Blank zeroes

; Convert 8-bit number into text, retain leading zeroes
C3057C:  STA $E0         ; Save number
         LDA #$03        ; Digits: 3
         STA $E4         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C30585:  STZ $E1         ; Digit: 0
         LDA.L C305AE,X  ; Power of 10
         INX             ; ROM index +1
         STA $E3         ; Save power
C3058E:  LDA $E0         ; Revised number
         SEC             ; Prepare SBC
         SBC $E3         ; Deduct power
         BCC C3059B      ; Branch if < 0
         STA $E0         ; Save changes
         INC $E1         ; Digit +1
         BRA C3058E      ; Loop
C3059B:  LDA $E1         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; Point to next
         DEC $E4         ; One less left
         BNE C30585      ; Loop till last
         RTS

; Powers of ten for the above
C305AE:  db $64          ; 100
         db $0A          ; 10
         db $01          ; 1

; Convert 16-bit number into text, blank leading zeroes
C305B1:  LDA #$05        ; Digits: 5
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C305B8:  REP #$20        ; 16-bit A
         LDA.L C305FB,X  ; Power of 10
         INX             ; ROM index +1
         INX             ; ROM index +1
         STA $ED         ; Save power
         STZ $EB         ; Digit: 0
C305C4:  SEC             ; Prepare SBC
         LDA $F3         ; Revised number
         SBC $ED         ; Deduct power
         BCC C305D1      ; Branch if < 0
         STA $F3         ; Save changes
         INC $EB         ; Digit +1
         BRA C305C4      ; Loop

; Fork: Convert digit into text
C305D1:  SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         DEC $E0         ; One less digit
         BNE C305B8      ; Loop till last

; Fork: Blank leading zeroes
C305E5:  LDY #$0004      ; Digits: 4
C305E_:  LDX $00         ; Index: 0
C305EA:  LDA $F7,X       ; Digit char
         CMP.B #!num0    ; Zero?
         BNE C305FA      ; Exit if not
         LDA #$FF        ; Space char
         STA $F7,X       ; Replace digit
         INX             ; Point to next
         DEY             ; One less left
         BNE C305EA      ; Loop till last
C305FA:  RTS

; Convert 24-bit number into text, blank leading zeroes
C30605:  STZ $F4         ; Number HB: 0
         LDA #$08        ; Digits: 8
         STA $E0         ; Set counter
         LDY $00         ; RAM index: 0
         TYX             ; ROM index: 0
C3060E:  REP #$20        ; 16-bit A
         STZ $EB         ; Digit: 0
C30612:  SEC             ; Prepare SBC
         LDA $F1         ; Number LBs
         SBC.L C30661,X  ; Deduct power's
         STA $F1         ; Save changes
         LDA $F3         ; Number HBs
         SBC.L C30671,X  ; Deduct power's
         BCC C30629      ; Branch if < 0
         STA $F3         ; Save changes
         INC $EB         ; Digit +1
         BRA C30612      ; Loop

; Fork: Cancel subtraction and convert digit
C30629:  LDA $F1         ; Number LBs
;        CLC             ; Prepare ADC
         ADC.L C30661,X  ; Reverse SBC
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         LDA $EB         ; Digit
         CLC             ; Prepare ADC
         ADC.B #!num0    ; Turn into text
         STA $00F7,Y     ; Set digit char
         INY             ; RAM index +1
         INX             ; ROM index +1
         INX             ; ROM index +1
         DEC $E0         ; One less digit
         BNE C3060E      ; Loop till last

; Fork: Blank leading zeroes
C3064B:  LDY #$0007      ; Digits: 7
         BRA C305E_      ; Blank zeroes

; Powers of ten, low bytes
C30661:  dw $9680        ; 10000000
         dw $4240        ; 1000000
         dw $86A0        ; 100000
C305FB:  dw $2710        ; 10000
         dw $03E8        ; 1000
         dw $0064        ; 100
         dw $000A        ; 10
         dw $0001        ; 1

; Powers of ten, high bytes
C30671:  dw $0098        ; 10000000
         dw $000F        ; 1000000
         dw $0001        ; 100000
         dw $0000        ; 10000
         dw $0000        ; 1000
         dw $0000        ; 100
         dw $0000        ; 10
         dw $0000        ; 1

; Load navigation parameters for menu area
C30681:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3
C30683:  STA $ED         ; Set src HB
         STY $EB         ; Set src LBs
         LDY $00         ; Index: 0
         LDA [$EB],Y     ; Wrap flags
         STA $59         ; Save in RAM
         INY             ; Index +1
         REP #$20        ; 16-bit A
         STZ $51         ; See C3/0758...
         LDA [$EB],Y     ; Initial spot
         STA $4D         ; Set cursor's
         INY             ; Index +1
         INY             ; Index +1
         LDA [$EB],Y     ; Rows, columns
         STA $53         ; Set boundaries
         STZ $4F         ; List col/row: 1
         SEP #$20        ; 8-bit A
         RTS

; Target party's leader
C306A1:  TDC             ; Clear A
         TAY             ; Member: 1st
C306A3:  TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $85,X       ; Empty slot?
         BNE C306B2      ; Exit if not
         INC $4E         ; Cursor row +1
         INY             ; Member slot +1
         CPY #$0004      ; Done all 4?
         BNE C306A3      ; Loop if not
C306B2:  RTS

; Set address to table of cursor coordinates
C306B3:  STY $E7         ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $E9         ; Set src HB
         RTS

; Position cursor in party area of Lineup menu
C306BA:  JSR C306B3      ; Set source
         JSR C306D3      ; Set list slot
         BRA C30748      ; Set coords

; Position cursor in unscrollable area
C306C3:  JSR C306B3      ; Set source
C306C6:  JSR C306FA      ; Set list slot
         BRA C30748      ; Set coords

; Position cursor in scrollable list
C306CB:  JSR C306B3      ; Set source
         JSR C30721      ; Set list slot
         BRA C30748      ; Set coords

; Set cursor's slot position in party area of Lineup menu
C306D3:  LDA $54         ; Row count
         XBA             ; Put in B
         LDA $4D         ; Cursor column
         JSR mul8        ; Multiply them
;        CLC             ; Prepare ADC
         ADC $4E         ; Add cursor row
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's slot position in unscrollable area
C306FA:  LDA $53         ; Column count
         XBA             ; Put in B
         LDA $4E         ; Cursor row
         JSR mul8        ; Multiply them
;        CLC             ; Prepare ADC
         ADC $4D         ; Add cursor col
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's slot position in scrollable list
C30721:  LDA $53         ; Column count
         XBA             ; Put in B
         LDA $50         ; List row
         JSR mul8        ; Row x count
;        CLC             ; Prepare ADC
         ADC $4F         ; Add list column
         STA $4B         ; Set cursor slot
         RTS

; Set cursor's position in pixels
C30748:  LDA $53         ; Column count
         DEC A           ; Adjust value
         CMP $4D         ; In range now?
         BCS C30760      ; Branch if so

; Fork: Invalid column (unused)
C30754:  SEC             ; Prepare SBC
         SBC $51         ; Minus 0...
         STA $E0         ; Use col qty -1
         STA $E2         ; Use last column
         BRA C30768      ; Validate row

; Fork: Valid column
C30760:  LDA $53         ; Column count
         STA $E0         ; Memorize it
         LDA $4D         ; Cursor column
         STA $E2         ; Memorize it

; Fork: Validate row
C30768:  LDA $54         ; Number of rows
         DEC A           ; Adjust value
         CMP $4E         ; In range now?
         BCS C30779      ; Branch if so

; Fork: Invalid row (unused)
C3076F:  SEC             ; Prepare SBC
         SBC $52         ; Minus 0...
;        STA $E1         ; Force last row
         BRA C3077B      ; Skip a line

; Fork: Valid row
C30779:  LDA $4E         ; Cursor row
C3077B:  STA $E1         ; Memorize it
         LDA $E0         ; Column count
         XBA             ; Put in B
         LDA $E1         ; Cursor row
         JSR mul8        ; Row x count
         ADC $E2         ; Add column
         ASL A           ; Double it
;        PHA             ; Push position
;        TDC             ; Clear A
;        PLA             ; Pull position
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$E7],Y     ; Coordinates
         STA $55         ; Set cursor's
         SEP #$20        ; 8-bit A
C307AF:  RTS

; Handle D-Pad for unscrollable list
C307B0:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C307D3      ; Branch if not
         LDA $4E         ; On top row?
         BNE C307CB      ; Go up if not
         LDA $59         ; Wrap flags
         LSR A           ; No V-Wrap?
         BCS C307AF      ; Exit if so
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor up
C307CB:  DEC $4E         ; Cursor row -1
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle down
C307D3:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C307F6      ; Branch if not
         LDA $54         ; Bottom row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C307EE      ; Go down if not
         LDA $59         ; Wrap flags
         LSR A           ; No V-Wrap?
         BCS C307AF      ; Exit if so
         STZ $4E         ; Cursor row: 1
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor down
C307EE:  INC $4E         ; Cursor row +1
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle left
C307F6:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C30815      ; Branch if not
         LDA $4D         ; On first column?
         BNE C3080E      ; Go left if not
         LDA $59         ; H-Wrap disabled?
         BMI C307AF      ; Exit if so
         LDA $53         ; Last column
         DEC A           ; Adjust value
         STA $4D         ; Set cursor column
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor left
C3080E:  DEC $4D         ; Cursor column -1
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle right
C30815:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C307AF      ; Exit if not
         LDA $53         ; Last column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C3082D      ; Go right if not
         LDA $59         ; H-Wrap disabled?
         BMI C307AF      ; Exit if so
         STZ $4D         ; Cursor column: 1
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor right
C3082D:  INC $4D         ; Cursor column +1
         JMP C30F0E      ; Sound: Cursor

; Queue movable cursor's OAM function
C30833:  LDY #C3083B     ; C3/083B
         JMP qanim1      ; Queue OAM fn

; Update movable cursor's sprite
C3083B:  BNE C3085F      ; If mode 1

; Mode 0: Initialize cursor
C30843:  LDY #C30912     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3F9A6      ; Follow BG1: Y

; Mode 1: Sustain cursor
C3085F:  LDA $46         ; Menu flags
         AND #$06        ; Remove cursors?
         BEQ C30880      ; Delete if so
         LDA $45         ; Menu flags
         BIT #$04        ; Hide cursor?
         BEQ C3087E      ; Exit if so
         LDY $55         ; Cursor pos
         JSR objpos      ; Set sprite's
         JSR C3128C      ; Define OAM
C3087E:  SEC             ; Set to requeue
         RTS             ; Exit
C30880:  CLC             ; Set to dequeue
         RTS

; Update blinking cursor marking prior choice
C30882:  BNE C308AE      ; If mode 1

; Mode 0: Initialize cursor
C3088E:  LDA #$01        ; Blinkers V1: On
         TSB $46         ; Set menu flag
         LDY #C3091B     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31271      ; Set pose timer
         JSR C3F9A6      ; Follow BG1: Y
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor
C308AE:  LDA $46         ; Menu flags
         LSR A           ; Remove blinkers?
         BCC C308EA      ; Delete if so
         REP #$21        ; 16-bit A; C-
         LDA $41         ; List V-Speed
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         ADC $344A,X     ; Add cursor's Y
         STA $344A,X     ; Set cursor's Y
         SEP #$20        ; 8-bit A
         LDA $46         ; Menu flags
         AND #$C0        ; Scrollable list?
         BEQ C308E5      ; Display if not

; Fork: Item menu
C308CD:  LDA $28         ; Blinker's slot
         AND #$FE        ; Get row x2
         INC A           ; Add 1
         STA $E0         ; Memorize it
         LDA $4A         ; Top onscreen row
         ASL A           ; Double it
         CLC             ; Prepare ADC
         ADC #$13        ; Get bottom row
         CMP $E0         ; Blinker's below?
         BCC C308E8      ; Blank if so
         LDA $4A         ; Top onscreen row
         ASL A           ; Double it
         CMP $E0         ; Blinker's above?
         BCS C308E8      ; Blank if so
C308E5:  JSR C3128C      ; Define OAM
C308E8:  SEC             ; Set to requeue
         RTS             ; Exit
C308EA:  CLC             ; Set to dequeue
         RTS

; Create a blinking cursor by every portrait
C30924:  TDC             ; Clear A
         TAX             ; Member: 1st
C30926:  LDA $85,X       ; Nobody here?
         BEQ C3094E      ; Skip if so
         PHX             ; Save index
         LDY #C30956     ; C3/0956
         JSR qanim1      ; Queue OAM fn
         PLY             ; Member index
         LDA $0085,Y     ; X position
         STA $7E33CA,X   ; Set cursor's
         LDA $0086,Y     ; Y position
         STA $7E344A,X   ; Set cursor's
         TYX             ; Char index
C3094E:  INX             ; Char index +1
         INX             ; Char index +1
         CPX #$0008      ; Done 4 chars?
         BNE C30926      ; Loop if not
         RTS

; Update blinking cursor not marking a prior choice
C30956:  BNE C3097E      ; If mode 1

; Mode 0: Initialize cursor
C3095E:  LDA #$08        ; Blinkers V2: On
         TSB $46         ; Set menu flag
         LDY #C3091B     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3F9A6      ; Follow BG1: Y

; Mode 1: Sustain cursor
C3097E:  LDA $46         ; Menu flags
         BIT #$08        ; Remove blinkers?
         BEQ C308EA      ; Delete if so
         JMP oamsec      ; Set OAM; requeue

; Update scrollbar animation index
C3098D:  LDA #$C0        ; Flashing: 2-ways
         TSB $46         ; Initialize index
         LDA $4A         ; At top of list?
         BNE C30999      ; Branch if not
         LDA #$40        ; Flashing: Down
         TRB $46         ; Update index
C30999:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BNE C309A3      ; Exit if not
         LDA #$80        ; Flashing: Up
         TRB $46         ; Update index
C309A3:  RTS

; Create a scrollbar on right side of screen
C309A4:  PHA             ; Save Y pos
         LDA #$E8        ; X: 232
         BRA C309B_      ; Skip 2 lines

; Create a scrollbar in middle of screen
C309B8:  PHA             ; Save Y pos
         LDA #$70        ; X: 112
C309B_:  PHA             ; Save X pos
         PHY             ; Save V-Speed
         LDY #C309CC     ; C3/09CC
         JSR qanim3      ; Queue OAM fn
         REP #$20        ; 16-bit A
         PLA             ; V-Speed
         STA $7E354A,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         PLA             ; X position
         STA $7E33CA,X   ; Set sprite's
         PLA             ; Y position
         STA $7E34CA,X   ; Set sprite's
         RTS

; Update scrollbar
C309CC:  BNE C309EF      ; If mode 1

; Mode 0: Initialize scrollbar
C309D4:  LDY #C30A4E     ; C3/0A4E
         JSR anm_c3      ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1
         LDA #$C0        ; Flash: Both ways
         TSB $46         ; Init anim index

; Mode 1: Sustain scrollbar
C309EF:  LDA $46         ; Menu flags
         AND #$C0        ; Hide scrollbar?
         BEQ C30A44      ; Delete if so
         JSR C3098D      ; Set anim index
C309FA:  LDY $354A,X     ; V-Speed
         LDA $4A         ; Scroll position
         JSR mul16       ; Speed x position
         LDX $2D         ; Queue index
         TDC             ; Clear A
         LDA $002135     ; Product MB
         ADC $34CA,X     ; Add base Y
         STA $344A,X     ; Set bar's Y
         LDA $46         ; Menu flags
         AND #$C0        ; Anim index
         LSR A           ; Put in b5-b6
         LSR A           ; Put in b4-b5
         LSR A           ; Put in b3-b4
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         TXY             ; Queue index
         TAX             ; Anim index
         REP #$20        ; 16-bit A
         LDA.L C30A46-2,X; Anim pointer
         STA $32C9,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue
C30A44:  CLC             ; Set to dequeue
         RTS

; Create portrait for member 1
C30A8D:  LDA #$15        ; Base Y: 21
         LDX $00         ; Member slot: 1
         BRA C30B0_      ; Create sprite

; Create portrait for member 2
C30AB6:  LDA #$45        ; Base Y: 69
         LDX #$0001      ; Member slot: 2
         BRA C30B0_      ; Create sprite

; Create portrait for member 3
C30AE1:  LDA #$75        ; Base Y: 117
         LDX #$0002      ; Member slot: 3
         BRA C30B0_      ; Create sprite

; Create portrait for member 4
C30B0C:  LDA #$A5        ; Base Y: 165
         LDX #$0003      ; Member slot: 4
C30B0_:  PHA             ; Save Y pos
         PHX             ; Save slot
         LDY #C30B7D     ; C3/0B7D
         JSR qanim3      ; Queue OAM fn
         JSR db7e        ; Set DB to 7E
         PLY             ; Member slot
         TXA             ; Queue index
         STA $0060,Y     ; Set sprite's
         JSR C30B5C      ; Set base X loc
         JSR C30B37      ; Load anim ptr
         PLA             ; Base Y pos
         STA $344A,X     ; Set sprite's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 00
         RTS

; Load pointer to animation table for portrait
C30B37:  LDA $0075,Y     ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
C30B3_:  PHX             ; Save queue index
         TAX             ; Index face slot
         REP #$20        ; 16-bit A
         LDA.L C30B54,X  ; Anim table ptr
         TAY             ; Put in Y
         PLX             ; Queue index
         JMP anm_c3      ; Set anim ptr

; Set portrait's base X position based on actor's row
C30B5C:  LDA #$02        ; Portrait bit
         BIT $45         ; Ignore row?
         BNE C30B6A      ; Branch if so
         LDA $0075,Y     ; Party info
         BIT #$20        ; In back row?
         BEQ C30B71      ; Branch if not
C30B6A:  LDA #$1A        ; Base X: 26
         BRA C30B76      ; Skip a line
C30B71:  LDA #$0E        ; Base X: 15
C30B76:  STA $33CA,X     ; Set sprite's X
         RTS

; Update actor portrait
C30B7D:  TAX             ; Index mode
         JMP (C30B81,X)  ; Handle mode

; Jump table for the above
C30B81:  dw C30B8B       ; Initialize data
         dw C30B95       ; Sustain portrait
         dw C30BA3       ; Set to shift right
         dw C30BB7       ; Set to shift left
         dw C30BC9       ; Shift left or right

; Mode 0: Initialize data
C30B8B:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         JSR C3F9A6      ; Follow BG1: Y
         JSR C31271      ; Set pose timer

; Mode 1: Sustain portrait
C30B95:  LDX $2D         ; Queue index
         LDA $35C9,X     ; Hide portrait?
         BMI C30BA1      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C30BA1:  CLC             ; Set to dequeue
         RTS

; Mode 2: Set to shift right
C30BA3:  LDA #$01        ; H-Speed: 1
;        LDX $2D         ; Queue index
;        STA $34CA,X     ; Set H-Speed
;        LDA #$0C        ; Frames: 12
;        STA $3349,X     ; Set shift timer
         BRA C30BB_      ; Shift once

; Mode 3: Set to shift left
C30BB7:  LDA #$FF        ; H-Speed: -1
C30BB_:  LDX $2D         ; Queue index
         STA $34CA,X     ; Set H-Speed
         LDA #$0C        ; Frames: 12
         STA $3349,X     ; Set shift timer

; Mode 4: Shift left or right
C30BC9:  LDX $2D         ; Queue index
         LDA #$04        ; Mode: 4
         STA $3649,X     ; Set sprite's
         LDY $3349,X     ; Timer expired?
         BEQ C30BEB      ; Freeze if so
         LDA $34CA,X     ; H-Speed
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add base X
         STA $33CA,X     ; Set sprite's
         DEC $3349,X     ; Timer -1
         JMP oamsec      ; Set OAM; requeue

; Fork: Set to stop moving
C30BEB:  LDA #$01        ; Mode: 1
         STA $3649,X     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Draw member's level, HP, and MP
C30CD7:  STX $EF         ; Pos tbl ptr LBs
         LDA #$C3        ; Bank: C3
         STA $F1         ; Set ptr HB
         LDX $67         ; Actor address
         LDA $08,X       ; Level
         JSR C30563      ; Turn into text
         REP #$20        ; 16-bit A
         LDA [$EF]       ; Tilemap ptr
         TAX             ; Move it to X
         JSR C30539      ; Draw level
         LDY $67         ; Actor address
         LDX $0B,Y       ; Max HP
         JSR C30DD0      ; Add gear bonus
         JSR C30DFD      ; Cap at 9999
         JSR C305B1      ; Turn into text
         LDY #$0004      ; Map ptr index
         JSR C30D8C      ; Draw max HP
         LDY $67         ; Actor address
         LDX $09,Y       ; Max MP
         STX $F3         ; Memorize it
         JSR C305B1      ; Turn into text
         LDY #$0002      ; Map ptr index
         JSR C30D8C      ; Draw HP
         JSR C30D96      ; Can use magic?
         BCC C30D5A      ; Hide MP if not
         LDY $67         ; Actor address
         LDX $0F,Y       ; Max MP
         JSR C30DD0      ; Add gear bonus
         JSR C30E0A      ; Cap at 999
         JSR C305B1      ; Turn into text
         LDY #$0008      ; Map ptr index
         JSR C30D8C      ; Draw max MP
         LDY $67         ; Actor address
         JSR C32C57      ; Truncate MP
         LDX $0D,Y       ; Current MP
         STX $F3         ; Memorize it
         JSR C305B1      ; Turn into text
         LDY #$0006      ; Map ptr index
         BRA C30D8C      ; Draw MP

; Fork: Hide MP
C30D5A:  REP #$20        ; 16-bit A
         LDY #$0006      ; Point to MP ptr
         LDA [$EF],Y     ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$0006      ; Point to "MP"
         STA $7E9E89     ; Set position
         LDY #$000C      ; Spaces: 12
         JMP spacedr     ; Draw 12 spaces

; Draw member's current or max HP or MP
C30D8C:  REP #$20        ; 16-bit A
         LDA [$EF],Y     ; Tilemap ptr
         TAX             ; Move it to X
         JMP C30513      ; Draw 4 digits

; Determine whether actor can use magic
C30D96:  LDX $1A69       ; Espers LBs
         BNE C30DCE      ; OK if got any
         LDX $1A6B       ; Espers HBs
         BNE C30DCE      ; OK if got any
         LDY $67         ; Actor's address
         JSR gogo2       ; Actor = Gogo?
         BEQ C30DCE      ; Allow if so
         BCS C30DCC      ; Deny Umaro/guest
         XBA             ; Put actor in B
         LDA #$36        ; Spell list size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         LDY #$0036      ; Spells left: 54
C30DC1:  LDA $1A6E,X     ; Spell mastery
         INC A           ; Fully learned?
         BEQ C30DCE      ; Allow if so
         INX             ; Point to next
         DEY             ; One less left
         BNE C30DC1      ; Loop till last
C30DCC:  CLC             ; Access: No
         RTS             ; Exit
C30DCE:  SEC             ; Access: Yes
         RTS

; Determine max HP or MP with gear bonus
C30DD0:  REP #$21        ; 16-bit A; C-
         TXA             ; Max HP or MP
         AND #$3FFF      ; Clear flags
         STA $E7         ; Memorize value
         TXA             ; Max HP or MP
         AND #$C000      ; Get bonus flags
         ROL A           ; Put in b7 & C
         ROL A           ; Put in C & b0
         ROL A           ; Put in b0-b1
         ROL A           ; Put in b1-b2
         TAX             ; Index them
         LDA $E7         ; Max HP or MP
         JMP (C30DE9,X)  ; Apply bonus

; Jump table for the above
C30DE9:  dw C30DF1       ; No bonus
         dw C30DF3       ; HP or MP + 25%
         dw C30DF4       ; HP or MP + 50%
         dw C30DF2       ; HP or MP + 12.5%

; Boost max HP or MP based on entry point
C30DF1:  TDC             ; Clear bonus
C30DF2:  LSR A           ; Halve bonus
C30DF3:  LSR A           ; Halve bonus
C30DF4:  LSR A           ; Halve bonus
         CLC             ; Prepare ADC
         ADC $E7         ; Add max value
         STA $F3         ; Memorize sum
         SEP #$20        ; 8-bit A
         RTS

; Enforce HP cap
C30DFD:  LDX $F3         ; Max HP
         CPX #$2710      ; Under 10000?
         BCC C30E09      ; Exit if so
         LDX #$270F      ; Enforce 9999
         STX $F3         ; Save changes
C30E09:  RTS

; Enforce MP cap
C30E0A:  LDX $F3         ; Max MP
         CPX #$03E8      ; Under 1000?
         BCC C30E16      ; Exit if so
         LDX #$03E7      ; Enforce 999
         STX $F3         ; Save changes
C30E16:  RTS

; Interchange cursor memory for swapped members
C30E25:  TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         ASL A           ; Double it
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $0236,X     ; B's Skills pos
         PHA             ; Memorize it
         LDA $0236,Y     ; A's Skills pos
         STA $0236,X     ; Set as B's
         PLA             ; B's Skills pos
         STA $0236,Y     ; Set as A's
         LDA $023E,X     ; B's Magic pos
         PHA             ; Memorize it
         LDA $023E,Y     ; A's Magic pos
         STA $023E,X     ; Set as B's
         PLA             ; B's Magic pos
         STA $023E,Y     ; Set as A's
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $28         ; Chosen slot A
         TAY             ; Index it
         LDA $0246,X     ; B's Magic bar
         PHA             ; Memorize pos
         LDA $0246,Y     ; A's Magic bar
         STA $0246,X     ; Set as B's
         PLA             ; B's Magic bar
         STA $0246,Y     ; Set as A's
         RTS

; Restore cursor position in inventory
C30E17:  LDY $022F       ; Old list pos
         STY $4F         ; Set as current
         TYA             ; List column
         STA $4D         ; Set as onscreen
         LDA $0231       ; Old scroll pos
         BRA C30E89      ; Restore it, etc.

; Restore cursor position in Skills menu
C30E6A:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $0236,X     ; Former position
         STY $4D         ; Set as current
         RTS

; Restore cursor position in Magic menu
C30E75:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $023E,X     ; Old list pos
         STY $4F         ; Set as current
         TYA             ; List column
         STA $4D         ; Set as onscreen
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $0246,X     ; Old scroll pos
C30E89:  STA $4A         ; Set as current
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $4A         ; Sub scroll pos
         STA $4E         ; Set onscreen row
         RTS

; Upload BG1 tilemaps A and B
C30E93:  PEI ($00)       ; VRAM: $0000
         LDY #$3849      ; 7E/3849
         BRA C30EF3      ; Move data

; Upload BG1 tilemaps B and C
C30EA1:  PEA $0400       ; VRAM: $0400
         LDY #$4049      ; 7E/4049
         BRA C30EF3      ; Move data

; Upload BG1 tilemaps C and D
C30EAF:  PEA $0800       ; VRAM: $0800
         LDY #$4849      ; 7E/4849
         BRA C30EF3      ; Move data

; Upload BG2 tilemaps A and B
C30EBD:  PEA $1000       ; VRAM: $1000
         LDY #$5849      ; 7E/5849
         BRA C30EF3      ; Move data

; Upload BG2 tilemaps C and D
C30ECB:  PEA $1800       ; VRAM: $1800
         LDY #$6849      ; 7E/6849
         BRA C30EF3      ; Move data

; Upload BG3 tilemaps A and B
C30ED9:  PEA $4000       ; VRAM: $4000
         LDY #$7849      ; 7E/7849
         BRA C30EF3      ; Move data

; Upload BG3 tilemaps C and D
C30EE7:  PEA $4800       ; VRAM: $4800
         LDY #$8849      ; 7E/8849
C30EF3:  STY $4302       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         PLY             ; VRAM ptr
         STY $2116       ; Set dest
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY #$1000      ; Bytes: 4096
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C30F0D:  RTS

; Play cursor sound
C30F0E:  LDA $AE         ; Started sound
         CMP #$21        ; Cursor's?
         BEQ C30F0D      ; Exit if so
C30F14:  LDA #$21        ; APU command
         STA $AE         ; Prevent repeat
         BRA C30F34      ; Set I/O port 0

; Play click sound
C30F1D:  LDA #$20        ; APU command
         BRA C30F34      ; Set I/O port 0

; Play save sound
C30F24:  LDA #$23        ; APU command
         BRA C30F34      ; Set I/O port 0

; Play buzzer sound
C30F2B:  LDA #$22        ; APU command
         BRA C30F34      ; Set I/O port 0

; Play letter deletion sound
C30F32:  LDA #$24        ; APU command
C30F34:  STA $002140     ; Set I/O port 0
         RTS

; Play cash register sound
C30F39:  LDA #$BF        ; Sound number
C30F3B:  STA $001301     ; Set I/O port 1
         LDA #$18        ; APU command
         STA $001300     ; Set I/O port 0
         LDA #$80        ; Volume specs
         STA $001302     ; Set I/O port 2
         JSL $C50004     ; Update ports
         RTS

; Play recovery sound
C30F50:  LDA #$C5        ; Sound number
         BRA C30F3B      ; Set vol, etc.

; Set to upload BG1 tilemaps A and B
C30F54:  JSR C30F68      ; Set src, dst
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap A
C30F68:  LDY $00         ; $0000
         STY $14         ; Set VRAM ptr
         LDY #$3849      ; 7E/3849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG1 tilemap B
C30F7C:  LDY #$0400      ; $0400
         STY $14         ; Set VRAM ptr
         LDY #$4049      ; 7E/4049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemaps A and B
C30F90:  LDY #$4000      ; $4000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 1)
C30FA4:  LDY #$4000      ; $4000
         STY $14         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 1)
C30FB8:  LDY #$4400      ; $4400
         STY $14         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $12         ; Set data size
         RTS

; Set to upload BG3 tilemap A (version 2)
C30FCC:  LDY #$4000      ; $4000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Set to upload BG3 tilemap B (version 2)
C30FE0:  LDY #$4400      ; $4400
         STY $1B         ; Set VRAM ptr
         LDY #$8049      ; 7E/8049
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         RTS

; Disable conditional upload during NMI
C30FF4:  STZ $1B         ; Null dst LB
         STZ $1C         ; Null dst HB
         RTS

; Set palette to black
black:   LDA #$C3        ; Source HB
         LDX #C3115F     ; Source LBs
         BRA C30FF_      ; Skip a line

; Load specified palette (for ending)
C30FF9:  LDA #$C2        ; Bank: C2
C30FF_:  STA $ED         ; Set src HB
         STX $EB         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         STY $E7         ; Set dst LBs
         LDY #$001F      ; Data index
C31007:  LDA [$EB],Y     ; Color data
         STA [$E7],Y     ; Save in RAM
         DEY             ; Index -1
         BPL C31007      ; Loop till < 0
         RTS

; Call function below, set slowness to 2
slow2:   LDA #$02        ; Slowness: 2
         BRA C31015      ; SKip a line

; Call function below, set slowness to 4
slow4:   LDA #$04        ; Slowness: 4

; Set to gradually convert one palette into another
C31015:  PHY             ; Save dst LBs
         PHX             ; Save src LBs
         PHA             ; Save slowness
         LDY #C31048     ; C3/1048
         JSR qanim0      ; Queue fade fn
         PLA             ; Fade slowness
         STA $7E37CA,X   ; Put in queue
         LDA #$7E        ; Dest HB
         STA $7E36C9,X   ; Put in queue
         LDA $ED         ; Source HB
         STA $7E36CA,X   ; Put in queue
         REP #$20        ; 16-bit A
         PLA             ; Source LBs
         STA $7E3449,X   ; Put in queue
         PLA             ; Dest LBs
         STA $7E33C9,X   ; Put in queue
         SEP #$20        ; 8-bit A
         RTS

; Gradually convert one palette into another
C31048:  BNE C31061      ; If mode 1

; Mode 0: Initialize timer
C31050:  LDA #$1F        ; Frames: 31
         STA $3349,X     ; Set fade timer
         STZ $334A,X     ; Timer HB: 0
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 1: Modify palette
C31061:  LDA $35C9,X     ; Delay over?
         BNE C3109D      ; Exit if not
         LDA $37CA,X     ; Slowness
         STA $35C9,X     ; Set delay
         LDA $36C9,X     ; Dest HB
         STA $E2         ; Memorize it
         LDA $36CA,X     ; Source HB
         STA $E5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $33C9,X     ; Dest LBs
         STA $E0         ; Memorize them
         LDA $3449,X     ; Source LBs
         STA $E3         ; Memorize them
         LDA $3349,X     ; Fade timer
         STA $F1         ; Memorize it
         JSR C310A2      ; Alter palette
         SEP #$20        ; 8-bit A
         LDX $2D         ; Queue index
         LDA $3349,X     ; Timer expired?
         BEQ C3109B      ; Dequeue if so
         DEC $3349,X     ; Fade timer -1
         BNE C3109D      ; Branch if > 0
C3109B:  CLC             ; Set to dequeue
         RTS             ; Exit
C3109D:  DEC $35C9,X     ; Fade delay -1
         SEC             ; Set to requeue
         RTS

; Partially convert one palette into another
C310A2:  LDX #$0010      ; Colors: 16
         LDY $00         ; Color index: 0
C310A7:  LDA [$E0],Y     ; Actual color
         STA $E7         ; Memorize it
         LDA [$E3],Y     ; Target color
         STA $E9         ; Memorize it
         JSR C310BC      ; Alter color
         STA [$E0],Y     ; Save changes
         INY             ; Color index +1
         INY             ; Color index +1
         DEX             ; One less color
         BNE C310A7      ; Loop till last
         RTS

; Partially convert one color into another
C310BC:  LDA $E7         ; Actual color
         AND #$001F      ; Get red
         STA $EB         ; Memorize it
         LDA $E9         ; Target color
         AND #$001F      ; Get red
         SEC             ; Prepare SBC
         SBC $EB         ; Both match?
         BEQ C310D9      ; Skip if so
         BCC C310D7      ; -1 if lesser
         CMP $F1         ; Diff < timer?
         BCC C310D9      ; Skip if so
         INC $EB         ; Red +1
         BRA C310D9      ; Skip a line
C310D7:  DEC $EB         ; Red -1

; Fork: Handle green
C310D9:  LDA $E7         ; Actual color
         AND #$03E0      ; Get green
         STA $ED         ; Memorize it
         LDA $E9         ; Target color
         AND #$03E0      ; Get green
         SEC             ; Prepare SBC
         SBC $ED         ; Both match?
         BEQ C31106      ; Skip if so
         BCC C310FE      ; -1 if lesser
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         XBA             ; Now 0-31
         CMP $F1         ; Diff < timer?
         BCC C31106      ; Skip if so
         CLC             ; Prepare ADC
         LDA $ED         ; Actual green
         ADC #$0020      ; Green +1
         STA $ED         ; Save changes
         BRA C31106      ; Do blue
C310FE:  LDA $ED         ; Actual green
         SEC             ; Prepare SBC
         SBC #$0020      ; Green -1
         STA $ED         ; Save changes

; Fork: Handle blue
C31106:  LDA $E7         ; Actual color
         AND #$7C00      ; Get blue
         STA $EF         ; Memorize it
         LDA $E9         ; Target color
         AND #$7C00      ; Get blue
         SEC             ; Prepare SBC
         SBC $EF         ; Both match?
         BEQ C31136      ; Skip if so
         BCC C3112E      ; -1 if lesser
         SEP #$20        ; 8-bit A
         XBA             ; ÷256
         LSR A           ; ÷512
         LSR A           ; Now 0-31
         REP #$20        ; 16-bit A
         CMP $F1         ; Diff < timer?
         BCC C31136      ; Skip if so
         CLC             ; Prepare ADC
         LDA $EF         ; Actual blue
         ADC #$0400      ; Blue +1
         STA $EF         ; Save changes
         BRA C31136      ; Merge RGB
C3112E:  LDA $EF         ; Actual blue
         SEC             ; Prepare SBC
         SBC #$0400      ; Blue -1
         STA $EF         ; Save changes

; Fork: Merge RGB components
C31136:  LDA $EB         ; Altered red
         ORA $ED         ; Add green
         ORA $EF         ; Add blue
         RTS

; White palette for an ending transition
C3113F:  dw $0000,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF
         dw $7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF,$7FFF

; Black palette for most ending transitions
C3115F:  dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
         dw $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

; Reset OAM and animation queue
C3117F:  JSR db7e        ; Set DB to 7E
;        STX $2F         ; No use...
         JSR C311B9      ; Reset OAM
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         TAX             ; Clear X
         STX $2D         ; Queue index: 0
         LDX #$3249      ; 7E/3249
         LDY #$0580      ; Bytes: 1408
         JMP clr_ram     ; Clear queue

; Reset OAM
C311B9:  LDX $00         ; Index: 0
         REP #$20        ; 16-bit A
C311BB:  LDA #$E001      ; X=1, Y=224
         STA $0300,X     ; Put offscreen
         INX             ; Index +1
         INX             ; Index +1
         LDA #$0001      ; Tile num: 1
         STA $0300,X     ; Set attribs
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0200      ; Past Lo-OAM?
         BNE C311BB      ; Loop if not
         SEP #$20        ; 8-bit A
         LDX #$001F      ; Hi-OAM index
C311D3:  STZ $0500,X     ; Clear Hi-OAM
         DEX             ; Index -1
         BPL C311D3      ; Loop till < 0
         RTS

; Queue animation function in slot 0 or further
qanim0:  TDC             ; Min slot: 0
         BRA C311DE      ; Queue anim fn

; Queue animation function in slot 8 or further
qanim1:  LDA #$01        ; Min slot: 8
         BRA C311DE      ; Queue anim fn

; Queue animation function in slot 16 or further
qanim2:  LDA #$02        ; Min slot: 16
         BRA C311DE      ; Queue anim fn

; Queue animation function in slot 24 or further
qanim3:  LDA #$03        ; Min slot: 24

; Queue animation function
C311DE:  PHA             ; Save slot
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         PLA             ; Starting slot
         JSR x16         ; x16
         REP #$20        ; 16-bit A
         TAX             ; Index it
C31201:  LDA $3249,X     ; Empty slot?
         BNE C3120B      ; Skip if not
         TYA             ; Animation fn
         STA $3249,X     ; Put in queue
         SEP #$20        ; 8-bit A
         LDA $2D         ; Caller's index
         STA $374A,X     ; Put in queue
;        INC $2F         ; No use...
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Fork: Try next slot
C3120B:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Past slot 64?
         BNE C31201      ; Loop if not
         STP             ; Freeze game...

; Process animation queue, hide inactive objects
C3121B:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDX #$0300      ; 7E/0300
         STX $0E         ; Set Lo-OAM ptr
         LDX #$0500      ; 7E/0500
         STX $10         ; Set Hi-OAM ptr
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Set Hi-OAM index
         STZ $34         ; Hi-OAM: 4x 8x8
         LDX #$0080      ; Objects: 128
         STX $31         ; Set space left
         LDX $00         ; Queue index: 0
         REP #$20        ; 16-bit A
C31239:  LDA $3249,X     ; Animation fn
         BEQ C31260      ; Skip if blank
         STX $2D         ; Set queue index
         PHX             ; Save index
         STA $2B         ; Set anim fn
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $3649,X     ; Anim mode
         ASL A           ; Double it
         PHB             ; Save DB
         JSR C3126E      ; Run anim fn
         PLB             ; Restore DB
         REP #$20        ; 16-bit A
         PLX             ; Queue index
         BCS C31260      ; Branch if kept
         STZ $3249,X     ; Anim fn: None
         STZ $3649,X     ; Anim mode: 0
         STZ $35C9,X     ; Misc. specs: 0
         STZ $3749,X     ; OAM complements
;        DEC $2F         ; No use...
C31260:  INX             ; Index +1
         INX             ; Index +1
         CPX #$0080      ; Done 64 slots?
         BNE C31239      ; Loop if not

; Fork: Hide inactive tiles in OAM
C313A3:  LDY $31         ; Unused tiles
         BEQ C313B7      ; Exit if none
         LDX #$01FC      ; Tile: Last
         LDA #$E001      ; X=1, Y=224
C313AD:  STA $0300,X     ; Set position
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEX             ; OAM index -1
         DEY             ; Tiles left -1
         BNE C313AD      ; Loop till last
C313B7:  SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Execute queued animation function
C3126E:  JMP ($002B)     ; Run anim fn

; Initialize M7 or object's pose number and timer
C3127_:  LDX $2D         ; Queue index
C31271:  REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB
         STZ $36C9,X     ; Pose: 1st
         LDY #$0002      ; Skip pose ptr
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set sprite's
         RTS

; Handle object's pose timer, then define OAM
C3128C:  JSR C31292      ; Pose timer -1
         BRA C312DE      ; Define OAM

; Handle pose or Mode 7 timer
C31292:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim ptr LBs
         STA $EB         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; Anim ptr HB
         STA $ED         ; Set src HB

; Fork: Handle control codes
C312A4:  LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Infinite?
         BEQ C312CD      ; Exit if so
;        CMP #$FF        ; Loop point?
         BCC C312B7      ; Branch if not
         STZ $36C9,X     ; Pose: 1st
         JSR C312CE      ; Set new timer
         BRA C312A4      ; Repeat checks

; Fork: Check if expired
C312B7:  LDA $36CA,X     ; Timer expired?
         BNE C312CA      ; Branch if not
         LDA $36C9,X     ; Pose index
         CLC             ; ...
         ADC #$03        ; Point to next
         STA $36C9,X     ; Save changes
         JSR C312CE      ; Set new timer
         BRA C312A4      ; Repeat checks

; Fork: Decrease timer
C312CA:  DEC $36CA,X     ; Timer -1
C312CD:  RTS

; Initialize pose or Mode 7 timer
C312CE:  TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         INY             ; Skip ptr LB
         INY             ; Skip ptr HB
         LDA [$EB],Y     ; Pose timer
         STA $36CA,X     ; Set object's
         RTS

; Define OAM for object's tiles
C312DE:  TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose OAM ptr
         STA $E7         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $35CA,X     ; OAM ptr HB
         STA $E9         ; Set src HB
         LDY $00         ; Index: 0
         LDA $31         ; OAM's full?
         BEQ C31366      ; Exit if so
         LDA [$E7],Y     ; Tile count
         STA $E6         ; Memorize it
         BEQ C31366      ; Exit if none
         INY             ; Index +1

; Fork: Large tile (16x16)
C31302:  LDA [$E7],Y     ; Tile X & flag
         STA $E0         ; Memorize them
         BPL C3131B      ; Branch if 8x8
         TDC             ; Clear A
         LDA $33         ; Hi-OAM index
         TAX             ; Index it
         LDA.L C3139F,X  ; Size flag
         CLC             ; Prepare ADC
         ADC $34         ; Add flag pack
         STA $34         ; Set flag pack
         STA ($10)       ; Put in Hi-OAM
         LDX $2D         ; Queue index
         BRA C3131F      ; Skip 2 lines

; Fork: Small tile (8x8)
C3131B:  LDA $34         ; OAM flag pack
         STA ($10)       ; Put in Hi-OAM
C3131F:  LDA $E0         ; Tile's X-Pos
         AND #$7F        ; Clear flag
         STA $E0         ; Save changes

; Fork: Pan with BG1
C31325:  LDA $364A,X     ; Sprite flags
         LSR A           ; Pan with BG1?
         BCC C31339      ; Branch if not
         STZ $E1         ; Tile's X HB: 0
         REP #$20        ; 16-bit A
         LDA $E0         ; Tile's rel X
         SEC             ; Prepare SBC
         SBC $35         ; Deduct BG1 X-Pos
         STA $E0         ; Save changes
         SEP #$20        ; 8-bit A

; Fork: Define Lo-OAM, do next tile
C31339:  JSR C31367      ; Adjust attribs
         DEC $33         ; Hi-OAM index -1
         BPL C3134A      ; Branch if 0+
         LDA #$03        ; Tile: 1 of 4
         STA $33         ; Reset size index
         STZ $34         ; Hi-OAM: 4x 8x8
         REP #$20        ; 16-bit A
         INC $10         ; Hi-OAM ptr +1
C3134A:  REP #$20        ; 16-bit A
         LDA $E0         ; Tile coords
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         LDA $E2         ; Tile num/attr
         STA ($0E)       ; Save in OAM
         INC $0E         ; Lo-OAM ptr +1
         INC $0E         ; Lo-OAM ptr +1
         SEP #$20        ; 8-bit A
         DEC $31         ; Space left -1
         BEQ C31366      ; Exit if full
         DEC $E6         ; Tiles left -1
         BNE C31302      ; Loop till last
C31366:  RTS

; Determine object tile's coordinates, load attributes
C31367:  LDA $E0         ; Tile's rel X
         CLC             ; Prepare ADC
         ADC $33CA,X     ; Add object's X
         STA $E0         ; Save changes
         INY             ; Index +1
         LDA [$E7],Y     ; Tile's rel Y
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add object's Y
         STA $E1         ; Memorize sum
         INY             ; Index +1
         LDA [$E7],Y     ; Tile num LSBs
         STA $E2         ; Memorize them
         INY             ; Index +1
         LDA $364A,X     ; Sprite flags
         BIT #$02        ; Mirror H-wise?
         BEQ C3138B      ; Branch if not
         LDA [$E7],Y     ; Tile attributes
         ORA #$40        ; Add H-Flip
         BRA C3138D      ; Skip a line
C3138B:  LDA [$E7],Y     ; Tile attributes
C3138D:  STA $E3         ; Memorize them
         LDA $3749,X     ; OAM complements
         BEQ C3139D      ; Exit if none
         LDA $E3         ; Tile attributes
         AND #$F1        ; Clear palette
         ORA $3749,X     ; Add complements
         STA $E3         ; Save changes
C3139D:  INY             ; Index +1
         RTS

; Hi-OAM complements
C3139F:  db $80          ; Tile 4: Large
         db $20          ; Tile 3: Large
         db $08          ; Tile 2: Large
         db $02          ; Tile 1: Large

; Trigger NMI, decode joypads, etc.
C313B8:  JSR C313D3      ; Trigger NMI
         LDA $46         ; Menu flags
         BIT #$20        ; Scroll list?
         BEQ C313C4      ; Branch if not
         JSR C38886      ; Scroll BG1
C313C4:  JSL C3AC99      ; Decode joypads
         LDA $20         ; Transition timer
         BEQ C313D2      ; Exit if off
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $08         ; No-autofire keys
         STY $0A         ; Semi-auto keys
C313D2:  RTS

; Trigger NMI, allow cursor sound to repeat
C313D3:  LDA #$81        ; Stop IRQ timers
         STA $4200       ; On: NMI, joypads
         STA $24         ; Mark NMI request
         CLI             ; Unmask IRQs
C313DB:  LDA $24         ; Back from NMI?
         BNE C313DB      ; Loop if not
         SEI             ; Mask IRQs
         LDA $44         ; Brightness
         STA $2100       ; Apply it now
         LDA $43         ; Queued HDMA
         STA $420C       ; Update channels
         LDA $B5         ; Mosaic settings
         STA $2106       ; Apply to screen
         STZ $AE         ; Allow SFX repeat
         RTS

; Handle NMI (menu, ending)
C313F2:  REP #$30        ; 16-bit A, X, Y
         PHA             ; Save A
         PHX             ; Save X
         PHY             ; Save Y
         PHB             ; Save DB
         PHD             ; Save DP
         SEP #$20        ; 8-bit A
         LDA $4210       ; Clear NMI flag
         LDA #$00        ; Clear A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         LDA $24         ; Manual NMI?
         BEQ C3141C      ; Branch if not
         JSR C3147D      ; Refresh screen
         LDY $CF         ; Ending timer
         INY             ; Ending timer +1
         STY $CF         ; Save changes
         LDY $20         ; Transition timer
         BEQ C3141C      ; Ignore if off
         DEY             ; Timer -1
         STY $20         ; Save changes
C3141C:  JSL $C00015     ; Event timers -1
         JSL C31433      ; Play time +1
         INC $23         ; NMI count +1
         TDC             ; Clear A
         STA $24         ; Unmark manual NMI
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Restore DP
         PLB             ; Restore DB
         PLY             ; Restore Y
         PLX             ; Restore X
         PLA             ; Restore A
         RTI

; Handle IRQ...
C31432:  RTI

; Advance play time (NMI)
C31433:  LDA $021E       ; Frames
         CMP #$3C        ; 60?
         BNE C31467      ; Branch if not

; Fork: Seconds +1
C3143C:  STZ $021E       ; Frames = 0
         LDA $021D       ; Seconds
         CMP #$3B        ; 59?
         BEQ C3144B      ; +1 min if so
         INC $021D       ; +1 second
         BRA C31467      ; +1 frame

; Fork: Minutes +1
C3144B:  STZ $021D       ; Seconds = 0
         LDA $021C       ; Minutes
         CMP #$3B        ; 59?
         BEQ C3145A      ; +1 hour if so
         INC $021C       ; +1 minute
         BRA C31467      ; +1 frame

; Fork: Hours +1
C3145A:  STZ $021C       ; Minutes = 0
         LDA $021B       ; Hours
         CMP #$63        ; 99?
         BEQ C31467      ; Branch if so
         INC $021B       ; +1 hour

; Fork: Frames +1
C31467:  LDX $021B       ; Hours and mins
         CPX #$3B63      ; 99:59?
         BNE C31478      ; Branch if not
         STZ $021D       ; Seconds = 0
C31478:  INC $021E       ; +1 frame
         TDC             ; Clear A
         RTL

; Refresh screen (NMI)
C3147D:  STZ $420C       ; Disable HDMA
         LDA $35         ; BG1 X-Pos LB
         STA $210D       ; Apply it now
         LDA $36         ; BG1 X-Pos HB
         STA $210D       ; Apply it now
         LDA $37         ; BG1 Y-Pos LB
         STA $210E       ; Apply it now
         LDA $38         ; BG1 Y-Pos HB
         STA $210E       ; Apply it now
         LDA $39         ; BG2 X-Pos LB
         STA $210F       ; Apply it now
         LDA $3A         ; BG2 X-Pos HB
         STA $210F       ; Apply it now
         LDA $3B         ; BG2 Y-Pos LB
         STA $2110       ; Apply it now
         LDA $3C         ; BG2 Y-Pos HB
         STA $2110       ; Apply it now
         LDA $3D         ; BG3 X-Pos LB
         STA $2111       ; Apply it now
         LDA $3E         ; BG3 X-Pos HB
         STA $2111       ; Apply it now
         LDA $3F         ; BG3 Y-Pos LB
         STA $2112       ; Apply it now
         LDA $40         ; BG3 Y-Pos HB
         STA $2112       ; Apply it now
         JSR C3E1E7      ; Refresh Mode 7
         JSR C314CE      ; Refresh OAM
         JSR C3153D      ; Refresh CGRAM
         JSR C314F3      ; Do VRAM DMA A
         BRA C31517      ; Do VRAM DMA B

; Refresh OAM (NMI)
C314CE:  LDX $00         ; $0000
         STX $2102       ; Set OAM address
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$04        ; $2104
         STA $4301       ; To OAM
         LDY #$0300      ; 00/0300
         STY $4302       ; Set src LBs
         STZ $4304       ; Src HB: 00
         LDY #$0220      ; Bytes: 544
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle absolute VRAM transfer (NMI)
C314F3:  LDY $14         ; Destination
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $16         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $18         ; Source HB
         STA $4304       ; Set CH0's
         LDY $12         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         RTS

; Handle conditional VRAM transfer (NMI)
C31517:  LDY $1B         ; Destination
         BEQ C3153C      ; Exit if none
         STY $2116       ; Set VRAM ptr
         LDA #$01        ; 2Rx1B to PPU
         STA $4300       ; Set DMA mode
         LDA #$18        ; $2118
         STA $4301       ; To VRAM
         LDY $1D         ; Source LBs
         STY $4302       ; Set CH0's
         LDA $1F         ; Source HB
         STA $4304       ; Set CH0's
         LDY $19         ; Number of bytes
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C3153C:  RTS

; Refresh CGRAM (NMI)
C3153D:  LDA $45         ; Menu flags
         LSR A           ; Freeze CGRAM?
         BCC C31568      ; Exit if so
         STZ $2121       ; To BG color 0
         LDA #$02        ; 1Rx2B to PPU
         STA $4300       ; Set DMA mode
         LDA #$22        ; $2122
         STA $4301       ; To CGRAM
         LDY #$3049      ; 7E/3049
         STY $4302       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4304       ; Set src HB
         LDY #$0200      ; Bytes: 512
         STY $4305       ; Set data size
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
C31568:  RTS

; Load save data on defeat
C31569:  LDA $021F       ; File number
         BEQ C3157F      ; Reset if none
         JSR C315CF      ; Load save file
         JSR C31A3A      ; Compute checksum
         JSR C31A54      ; Bad checksum?
         BEQ C3157F      ; Reset game if so
         JSR C315FE      ; Move timer data
         TDC             ; Reset game: No
         BRA C31583      ; Set aftereffect

; Fork: Reset game
C3157F:  LDA #$FF        ; Reset game: Yes
C31583:  STA $0205       ; Set aftereffect
         TDC             ; ...
         RTL

; Record game data
C31588:  STA $307FF0     ; Set last altered
         STA $0224       ; Set last viewed
         PHA             ; Memorize slot
         LDY $021B       ; Hrs, mins played
         STY $1863       ; To SRAM block
         LDA $021D       ; Seconds played
         STA $1865       ; To SRAM block
         JSR C315EF      ; Move timer data
         JSR C31A3A      ; Compute checksum
         STY $1FFE       ; Put in SRAM block
         TDC             ; Clear A
         PLA             ; File number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C315C7-2,X; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C315B6:  LDA $1600,Y     ; Game data
         STA $306000,X   ; Save in SRAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C315B6      ; Loop if not
         JMP C37817      ; Mark all files

; SRAM pointers
C315C7:  dw $0000        ; Save slot 1
         dw $0A00        ; Save slot 2
         dw $1400        ; Save slot 3

; Load save file
C315CF:  PHA             ; Push file
         TDC             ; Clear A
         PLA             ; Pull file
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C315C7-2,X; SRAM pointer
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY $00         ; RAM index: 0
C315E0:  LDA $306000,X   ; Saved data
         STA $1600,Y     ; Copy to RAM
         INX             ; SRAM index +1
         INY             ; RAM index +1
         CPY #$0A00      ; At $2000?
         BNE C315E0      ; Loop if not
         RTS

; Copy event timer data to save area
C315EF:  LDX #$0017      ; Base index
C315F1:  LDA $1188,X     ; Timer data
         STA $1FA8,X     ; Put in SRAM
         DEX             ; Index -1
         BPL C315F1      ; Loop till < 0
         RTS

; Restore saved event timer data
C315FE:  LDX #$0017      ; Base index
C31600:  LDA $1FA8,X     ; Timer data
         STA $1188,X     ; Make active
         DEX             ; Index -1
         BPL C31600      ; Loop till < 0
         RTS

; Handle D-Pad for Save menu
C31613:  JSR C307B0      ; Handle D-Pad
C31616:  LDY #C31637     ; C3/1637
         JMP C306C3      ; Relocate cursor

; Handle D-Pad for Load menu
C31627:  JSR C307B0      ; Handle D-Pad
C3162A:  LDY #C31635     ; C3/1635
         JMP C306C3      ; Relocate cursor

; Load navigation data for save file confirmation
C3163D:  LDY #C3164C     ; C3/164C
         JMP C30681      ; Load navig data

; Handle D-Pad for save file confirmation
C31643:  JSR C307B0      ; Handle D-Pad
C31646:  LDY #C31651     ; C3/1651
         JMP C306C3      ; Relocate cursor

; Draw Save menu, load skins, list actor sprites
C31655:  JSR C371BC      ; Clear BG2 map A
         JSR C3169B      ; Handle files
         JSR C33B5B      ; Load skin visuals
         LDX #C31905     ; C3/1905
         JSR C303C4      ; Draw top window
         JSR C3D24D      ; Color: User's
         LDY #C31AE1     ; Text pointer
         JSR C30326      ; Draw "Save"
         BRA C318F9      ; Upload tilemaps

; Draw Load menu, load skins, list actor sprites
C31671:  JSR C371BC      ; Clear BG2 map A
         STZ $1D4E       ; Skin: 1st; etc.
         JSR C37350      ; Reset skin colors
         JSR C33B5B      ; Load skin visuals
         LDX #C31905     ; C3/1905
         JSR C303C4      ; Draw top window
         LDA $1D4E       ; Game options
         AND #$70        ; Reset skin, gauge
         STA $1D4E       ; Save changes
         JSR C3169B      ; Handle files
         JSR C3D24D      ; Color: User's
         LDY #C31AE7     ; Text pointer
         JSR C30326      ; Draw "New Game"
C318F9:  JMP C363D4      ; Upload tilemaps

; Output all save files
C3169B:  JSR C373F4      ; Load grayscale
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         LDY #$7FFF      ; Color: White
         JSR C340B_      ; Put in palettes
         LDA #$01        ; Gradient set: 1
         JSL $D4CA1D     ; Create gradient
         JSR C371A9      ; Clear BG1 map A
         JSR C371D0      ; Clear BG3 map A
         JSR C371DA      ; Clear BG3 map C
         JSR C31915      ; Move game's SRAM

; Fork: Load save file 1
C316CC:  LDA #$01        ; File: 1
         JSR C315CF      ; Load save file
         JSR C37087      ; Move party info
         JSR C31A3A      ; Compute checksum
         JSR C31A54      ; Test validity
         STY $91         ; Save checksum
         BEQ C316EB      ; Branch if invalid
         JSR C376F5      ; List char sprites
         JSR C31786      ; Draw file 1 text
         JSR C33BC9      ; Load skin colors
         BRA C316FE      ; Handle file 2

; Fork: Blank file 1
C316EB:  JSR C3192A      ; Restore skin 1
         JSR C376F5      ; Use blank party
         JSR C3D24D      ; Color: White
         LDY #C31A8D     ; Text pointer
         JSR C302F9      ; Draw "EMPTY"
         JSR C33BC9      ; Load skin 1 pal

; Fork: Load save file 2
C316FE:  LDA #$02        ; File: 2
         JSR C315CF      ; Load save file
         JSR C37087      ; Move party info
         JSR C31A3A      ; Compute checksum
         JSR C31A54      ; Test validity
         STY $93         ; Save checksum
         BEQ C3171D      ; Branch if invalid
         JSR C3774C      ; List char sprites
         JSR C31833      ; Draw file 2 text
         JSR C33BDD      ; Load skin colors
         BRA C31730      ; Handle file 3

; Fork: Blank file 2
C3171D:  JSR C3192A      ; Restore skin 1
         JSR C3774C      ; Use blank party
         JSR C3D24D      ; Color: White
         LDY #C31A95     ; Text pointer
         JSR C302F9      ; Draw "EMPTY"
         JSR C33BDD      ; Load skin 1 pal

; Fork: Load save file 3
C31730:  LDA #$03        ; File: 3
         JSR C315CF      ; Load save file
         JSR C37087      ; Move party info
         JSR C31A3A      ; Compute checksum
         JSR C31A54      ; Test validity
         STY $95         ; Save checksum
         BEQ C3174F      ; Branch if invalid
         JSR C37770      ; List char sprites
         JSR C31896      ; Draw file 3 text
         JSR C33BF1      ; Load skin colors
         BRA C31762      ; Draw all windows

; Fork: Blank file 3
C3174F:  JSR C3192A      ; Restore skin 1
         JSR C37770      ; Use blank party
         JSR C3D24D      ; Color: White
         LDY #C31A9D     ; Text pointer
         JSR C302F9      ; Draw "EMPTY"
         JSR C33BF1      ; Load skin 1 pal

; Fork: Draw windows and upload skins
C31762:  JSR C3192A      ; Restore SRAM
         JSR C33B75      ; Upload skin A
         LDX #C31909     ; C3/1909
         JSR C303C4      ; Draw window A
         JSR C33B91      ; Upload skin B
         LDX #C3190D     ; C3/190D
         JSR C303C4      ; Draw window B
         JSR C33BAD      ; Upload skin C
         LDX #C31911     ; C3/1911
         JSR C303C4      ; Draw window C
         LDY #$1C00      ; Palette: 7
         JMP C303A9      ; Build skin map

; Draw all text for save file 1
C31786:  JSR C3D24D      ; Color: White
         LDY #C31ABA     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C30563      ; Turn into text
         LDX #$7B0D      ; Text position
         JSR C30539      ; Draw hours
         LDA $1864       ; Minutes played
         JSR C3057C      ; Turn into text
         LDX #$7B13      ; Text position
         JSR C30539      ; Draw minutes
         JSR C317B6      ; Draw leader info
         JSR C3D252      ; Color: Blue
         LDY #C31AA5     ; Text pointer
         JMP C302F9      ; Draw "TIME"

; Draw leader info for save file 1
C317B6:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C317B8:  LDA $69,X       ; Actor in slot
         BPL .okay       ; Branch if any
         INX             ; Member slot +1
         BRA C317B8      ; Try next member
.okay    JSR C31827      ; Get its address
         JSR C3D252      ; Color: Blue
         LDY #C31AC6     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3D24D      ; Color: White
         LDY #C31AD5     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3A0F       ; Name position
         PEA $7AFD       ; Max HP position
         PEA $7AF3       ; HP position
         PEA $7A81       ; Level position
;        BRA C317E8      ; Draw stats

; Draw leader's stats over save file
C317E8:  LDX $67         ; Actor's address
         LDA $08,X       ; Level
         JSR C30563      ; Turn into text
         PLX             ; Text position
         JSR C30539      ; Draw 2 digits
         LDY $67         ; Actor's address
         JSR C32C35      ; Truncate HP
         LDX $09,Y       ; Current HP
         STX $F3         ; Memorize it
         JSR C305B1      ; Turn into text
         PLX             ; Text position
         JSR C30513      ; Draw 4 digits
         LDY $67         ; Actor address
         LDX $0B,Y       ; Max HP
         JSR C30DD0      ; Add gear bonus
         JSR C30DFD      ; Cap at 9999
         JSR C305B1      ; Turn into text
         PLX             ; Text position
         JSR C30513      ; Draw 4 digits
         PLY             ; Text position
         JMP C3356A      ; Draw actor name

; Get member's SRAM block address
C31827:  TDC             ; Clear A
         TXA             ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; SRAM address
         STX $67         ; Save for later
         RTS

; Draw all text for save file 2
C31833:  JSR C3D24D      ; Color: White
         LDY #C31ABE     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C30563      ; Turn into text
         LDX #$7CCD      ; Text position
         JSR C30539      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C3057C      ; Turn into text
         LDX #$7CD3      ; Text position
         JSR C30539      ; Draw 2 digits
         JSR C31863      ; Draw leader info
         JSR C3D252      ; Color: Blue
         LDY #C31AAC     ; Text pointer
         JMP C302F9      ; Draw "TIME"

; Draw leader info for save file 2
C31863:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C31865:  LDA $69,X       ; Actor in slot
         BMI C31893      ; Skip if empty
         JSR C31827      ; Get its address
         JSR C3D252      ; Color: Blue
         LDY #C31ACB     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3D24D      ; Color: White
         LDY #C31AD9     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3BCF       ; Name position
         PEA $7CBD       ; Max HP position
         PEA $7CB3       ; HP position
         PEA $7C41       ; Level position
         JMP C317E8      ; Draw stats
C31893:  INX             ; Member slot +1
         BRA C31865      ; Try next member

; Draw all text for save file 3
C31896:  JSR C3D24D      ; Color: White
         LDY #C31AC2     ; Text pointer
         JSR C302F9      ; Draw ":"
         LDA $1863       ; Hours played
         JSR C30563      ; Turn into text
         LDX #$7E8D      ; Text position
         JSR C30539      ; Draw 2 digits
         LDA $1864       ; Minutes played
         JSR C3057C      ; Turn into text
         LDX #$7E93      ; Text position
         JSR C30539      ; Draw 2 digits
         JSR C318C6      ; Draw leader info
         JSR C3D252      ; Color: Blue
         LDY #C31AB3     ; Text pointer
         JMP C302F9      ; Draw "TIME"

; Draw leader info for save file 3
C318C6:  TDC             ; Clear A
         TAX             ; 1st: Member 1
C318C8:  LDA $69,X       ; Actor in slot
         BMI C318F6      ; Skip if empty
         JSR C31827      ; Get its address
         JSR C3D252      ; Color: Blue
         LDY #C31AD0     ; Text pointer
         JSR C302F9      ; Draw "LV"
         JSR C3D24D      ; Color: White
         LDY #C31ADD     ; Text pointer
         JSR C302F9      ; Draw "/"
         PEA $3D8F       ; Name position
         PEA $7E7D       ; Max HP position
         PEA $7E73       ; HP position
         PEA $7E01       ; Level position
         JMP C317E8      ; Draw stats
C318F6:  INX             ; Member slot +1
         BRA C318C8      ; Try next member

; Back up SRAM block
C31915:  LDX #$09FF      ; Init index
C3191D:  LDA $1600,X     ; SRAM data
         STA $7EAC8D,X   ; Make backup
         DEX             ; Index -1
         BPL C3191D      ; Loop till < 0
         RTS

; Restore SRAM block
C3192A:  LDX #$09FF      ; Init index
C3192C:  LDA $7EAC8D,X   ; Data backup
         STA $1600,X     ; Restore it
         DEX             ; Index -1
         BPL C3192C      ; Loop till < 0
         RTS

; Set to condense BG3 text (save file confirmation, Colosseum matchup)
C3193A:  LDY #C31959     ; C3/1959
         JMP bg3v_       ; Queue BG3 V-Pan

; Create actor sprites for Save or Load menu
C3196C:  LDX $00         ; Actor slot: 1
C3196E:  LDA $7EAA71,X   ; Empty slot?
         BMI C319E0      ; Skip if so
         PHX             ; Save slot
         PHX             ; Save slot
         LDY #C31A30     ; C3/1A30
         JSR qanim3      ; Queue OAM fn
         TXY             ; Queue index
         PLX             ; Actor slot
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDA $66         ; On "New Game"?
         BEQ C3199A      ; Branch if so
         DEC A           ; On file 1?
         BEQ C319AC      ; Branch if so
         DEC A           ; On file 2?
         BEQ C319A3      ; Branch if so
         LDA.L C31A24,X  ; OAM complements
         BRA C319B0      ; Set coords/ptr

; Fork: New Game
C3199A:  LDA.L C31A00,X  ; OAM complements
         BRA C319B0      ; Set coords/ptr

; Fork: Save file 2
C319A3:  LDA.L C31A18,X  ; OAM complements
         BRA C319B0      ; Set coords/ptr

; Fork: Save file 1
C319AC:  LDA.L C31A0C,X  ; OAM complements
C319B0:  STA $3749,Y     ; Set sprite's
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set anim ptr HB
         LDA.L C319E8,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C319F4,X  ; Y position
         STA $344A,Y     ; Set sprite's
         TDC             ; Clear A
         LDA $AA71,X     ; Graphics set
         JSR C3808E      ; Set anim ptr
         PLB             ; Restore DB
         PLX             ; Actor slot
C319E0:  INX             ; Point to next
         CPX #$000C      ; Done all 12?
         BNE C3196E      ; Loop if not
;        SEC             ; Set to requeue
         RTS

; Display actor's sprite on save file
C31A30:  JSR C3127_      ; Set pose timer
         JSR C3128C      ; Define OAM
         CLC             ; Set to dequeue
         RTS

; Compute SRAM checksum
C31A3A:  LDX #$09FD      ; SRAM index
         TDC             ; Checksum: 0
.loop    CLC             ; Prepare ADC
         ADC $1600,X     ; Add SRAM byte
         BCC .next       ; If no overflow
         XBA             ; Checksum HB
         INC A           ; Add one
         XBA             ; Checksum LB
.next    DEX             ; SRAM index -1
         BPL .loop       ; Loop till < 0
         TAY             ; Put sum in Y
         RTS

; Load and validate SRAM checksum (buggy if zero)
C31A54:  CPY $1FFE       ; Sum in save file
         BEQ C31A60      ; Exit if identical
         LDY $00         ; Clear checksum
C31A60:  TYX             ; Z-Flag = Validity
         RTS

; 53: Queue fade-out for save menu
C31A64:  JSR C330EA      ; Queue fade-out
         BRA C31A76      ; Skip a line

; 52: Queue fade-in for save menu
C31A73:  JSR C330F1      ; Queue fade-in
C31A76:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$54        ; C3/1A82
         STA $26         ; Next: Wait
         BRA C31A8A      ; Create actors

; 54: Wait while save menu fades in or out
C31A82:  LDY $20         ; Timer expired?
         BNE C31A8A      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31A8A:  JMP C3196C      ; Refresh actors

; 04: Initialize main menu
C31AF0:  JSR C335F7      ; Reset/Stop stuff
         JSR C31C0E      ; Load portraits
         JSR C30FF4      ; Stop VRAM DMA B
         JSR C33B3F      ; Set Win2 bounds
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         JSR C37076      ; Reset BGs' X/Y
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$43        ; 64x64 at $4000
         STA $2109       ; Set BG3 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C33190      ; Draw menu
         LDY #C32FDD     ; C3/2FDD
         JSR qanim0      ; Queue D-Pad fn
         JSR C30833      ; Queue cursor OAM
         JSR C33616      ; HDMA: MS desig.
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C3376B      ; Set to shift BG3
         LDA #$05        ; C3/1E0A
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 07: Initialize Item menu
C31B3C:  JSR C31B48      ; Init list vars
         JSR C31B64      ; Draw menu; cursor
         JSR C31B74      ; Shift & OBJ & Fade
         BRA C31B94      ; Queue: Choice 1

; Initialize item list variables (Item, Colosseum)
C31B48:  JSR C335F7      ; Reset/Stop stuff
         JSR C31BFF      ; Queue desc anim
         JSR C37076      ; Reset BGs' X/Y
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$76        ; Top row: 119th
         STA $5C         ; Set scroll limit
         LDX #$020A      ; Onscreen rows: 10
         STX $5A         ; Onscreen cols: 2
         JMP C384A3      ; Load navig data

; Draw Item menu, position cursor in inventory
C31B64:  LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C31B6E      ; Branch if not
         JSR C30E17      ; Restore cursor
C31B6E:  JSR C384AC      ; Relocate cursor
         JMP C38552      ; Draw menu; elems

; Initiate text shifting, sprites, fade-in (Item, Colosseum)
C31B74:  JSR C385DA      ; Set to shift text
         JSR C30833      ; Queue cursor OAM
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C3CB5_      ; Create scrollbar

; Queue Item menu choice 1, prepare fade-in
C31B94:  LDA #$08        ; C3/1F5D
         STA $27         ; Queue: Choice 1
         JMP C33609      ; BRT:1 + NMI

; 77: Return from item usage menu
C31B9B:  JSR C31B48      ; Init list vars
         JSR oldcur      ; Restore cursor pos
         JSR C384AC      ; Relocate cursor
         JSR C38552      ; Draw menu; elems
         JSR C31B74      ; Shift & OBJ & Fade
         BRA C31B94      ; Queue: Choice 1

; 09: Initialize Skills menu
C31BC1:  JSR C335F7      ; Reset/Stop stuff
         TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor in slot
         JSL $C20006     ; Get actor stats
         JSR C31C0E      ; Load portraits
         JSR C3719C      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C35482      ; Set to shift text
         JSR C3533D      ; Draw menu, etc.
         JSR C35213      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C31BEB      ; Branch if not
         JSR C30E6A      ; Restore cursor
C31BEB:  JSR C3521C      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C31BFF      ; Queue desc anim
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$0A        ; C3/205A
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; Set to update and upload description
C31BFF:  JSR C3B0D9      ; Clear desc GFX
         JSR C3B301      ; Queue desc upload
         LDY #C3B151     ; C3/B151
         JMP qanim0      ; Queue desc update

; Load portrait graphics and colors for party
C31C0E:  JSR C37087      ; Get party info
         JSR C37616      ; Load graphics
         JSR C3739D      ; Load colors
         LDA #$05        ; Show cursor: Y
         TSB $45         ; Unfreeze CGRAM
         JMP C3153D      ; Refresh CGRAM

; 35: Initialize Equip menu
C31C1E:  JSR C31C23      ; Init variables
C31C3D:  JSR C397DB      ; Draw menu; status
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$36        ; C3/9E10
         STA $27         ; Queue: Option list
         JMP C33609      ; BRT:1 + NMI

; Initialize variables for Equip menu
C31C23:  JSR C335F7      ; Reset/Stop stuff
         JSR C3719C      ; Set Win1 bounds
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C39CA5      ; Set to shift text
         JSR C395C5      ; Load navig data
         JSR C395CE      ; Relocate cursor
         JMP C30833      ; Queue cursor OAM

; 7E: Swap actor in Equip menu, retain Equip mode
C31C4B:  JSR C31C67      ; Draw menu, etc.
         JSR C39E3E      ; Draw blue "EQUIP"
         JSR C31C70      ; Cursor & Fade-in
         LDA #$55        ; C3/A073
         BRA C31C7B      ; Queue slot choice

; 7F: Swap actor in Equip menu, retain Remove mode
C31C59:  JSR C31C67      ; Draw menu, etc.
         JSR C39E45      ; Draw blue "REMOVE"
         JSR C31C70      ; Cursor & Fade-in
         LDA #$56        ; C3/A0BE
;        BRA C31C7B      ; Queue slot choice

; Set queued menu command, prepare fade-in
C31C7B:  STA $27         ; Set queued cmd
         JMP C33609      ; BRT:1 + NMI

; Redraw Equip menu after actor swap
C31C67:  JSR C31C23      ; Reset variables
         JSR C397DB      ; Draw menu; status
         JMP C39E03      ; Switch windows

; Put cursor on first gear slot, trigger fade-in
C31C70:  LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JSR C395E1      ; Load navig data
         JMP C395EA      ; Relocate cursor

; 6D: Open Equip menu after optimizing gear
C31C80:  JSR C31C23      ; Init variables
         JSR C39EDF      ; Optimize gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31C3D      ; Draw menu, etc.

; 6E: Open Equip menu after removing all gear
C31C8C:  JSR C31C23      ; Init variables
         JSR C39E97      ; Remove gear
         LDA #$02        ; Menu: Equip
         STA $25         ; Set submenu
         BRA C31C3D      ; Draw menu, etc.

; 38: Initialize party gear overview
C31C98:  JSR C335F7      ; Reset/Stop stuff
         JSR C39C86      ; Set to shift text
         JSR C39662      ; Draw menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$39        ; C3/29D0
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; 0B: Initialize Status menu
C31CAC:  JSR C335F7      ; Reset/Stop stuff
         JSR C36854      ; Set to shift text
         JSR C36362      ; Draw menu; portrait
         JSR C31CC3      ; Init cursor data
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$0C        ; C3/2255
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; Initialize cursor data for Status menu
C31CC3:  JSR gogo1       ; Actor = Gogo?
         BNE C31CDE      ; Abort if not
         JSR C337C7      ; Load navig data
         JSR C337D0      ; Relocate cursor
         LDA #$06        ; Main cursor: On
         TSB $46         ; Set menu flag
         JMP C30833      ; Queue cursor OAM
C31CDE:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         RTS

; 0D: Initialize Config menu
C31CE3:  JSR C335F7      ; Reset/Stop stuff
         STZ $4A         ; Screen: 1st
         JSR C33B20      ; Set Win2 bounds
         JSR C3396F      ; Draw menu, etc.
         JSR C33927      ; Load navig data
         LDA $5F         ; Return position
         STA $4E         ; Set cursor row
         JSR C33930      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$0E        ; C3/2325
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; 13: Initialize Save menu
C31D06:  JSR C335F7      ; Reset/Stop stuff
;        LDY #$0002      ; Y: 2
;        STY $37         ; Set BG1 Y-Pos
;        JSR C3376B      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
         JSR C31655      ; Draw menu, get chars
         JSR C3745B      ; Load actor colors
         JSR C37418      ; Load cursor colors
         LDY #C3161C     ; C3/161C
         JSR C30681      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31D2D      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31D2D      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31D33      ; Branch if 0
C31D2D:  LDA $0224       ; Last viewed file
         DEC A           ; Now 0-2
         STA $4E         ; Set cursor row
C31D33:  JSR C31616      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set active file
         LDA #$52        ; C3/1A73
         STA $26         ; Next: Fade-in
         LDA #$14        ; C3/25B3
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; 15: Initialize save confirmation
C31D49:  JSR C335F7      ; Reset/Stop stuff
         JSR C37087      ; Get party info
         JSR C331C3      ; Draw menu
         JSR C3163D      ; Load navig data
         JSR C31646      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C3193A      ; Set to shift text
         LDA #$16        ; C3/2610
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 20: Initialize Load menu
C31D69:  JSR C335F7      ; Reset/Stop stuff
;        JSR C3376B      ; Set to shift BG3...
         LDA #$E3        ; CH: 0-1, 5-7
         TRB $43         ; Halt HDMA channels
;        LDY $00         ; X: 0
;        STY $35         ; Set BG1 X-Pos
;        STY $39         ; Set BG2 X-Pos
;        STY $3D         ; Set BG3 X-Pos
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C31671      ; Draw menu, get chars
         JSR C3745B      ; Load actor colors
         JSR C37418      ; Load cursor colors
         LDY #C31630     ; C3/1630
         JSR C30681      ; Load navig data
         LDY $91         ; File 1 checksum
         BNE C31D9C      ; Branch if not 0
         LDY $93         ; File 2 checksum
         BNE C31D9C      ; Branch if not 0
         LDY $95         ; File 3 checksum
         BEQ C31DA2      ; Branch if 0
C31D9C:  LDA $307FF0     ; Last altered file
         STA $4E         ; Set cursor row
C31DA2:  JSR C3162A      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA $4B         ; Cursor slot
         STA $66         ; Set active file
         LDA #$21        ; C3/2A5D
         STA $27         ; Queue: Sustain menu
         LDA #$52        ; C3/1A73
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 22: Initialize load confirmation
C31DB7:  JSR C335F7      ; Reset/Stop stuff
         JSR C37087      ; Get party info
         JSR C331E7      ; Draw menu
         JSR C3163D      ; Load navig data
         JSR C31646      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C3193A      ; Set to shift text
         LDA #$23        ; C3/2AC5
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 00: Queue fade-out, prepare transition
C31DD7:  JSR C330EA      ; Queue fade-out
         BRA C31DE7      ; Skip a line

; 01: Queue fade-in, prepare transition
C31DE4:  JSR C330F1      ; Queue fade-in
C31DE7:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$02        ; C3/1DF1
         STA $26         ; Next: Wait
         RTS

; 02: Wait while menu fades in or out
C31DF1:  LDY $20         ; Timer expired?
         BNE C31DF9      ; Exit if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C31DF9:  RTS

; 03: Exit main menu's portrait area
C31DFA:  LDA #$05        ; C3/1E0A
         STA $26         ; Next: Main menu
         LDY #C32FDD     ; C3/2FDD
         JSR qanim0      ; Queue D-Pad fn
         JMP C30833      ; Queue cursor OAM

; 05: Sustain main menu
C31E0A:  JSR C33610      ; Redraw time
         LDA $08         ; Pushing A?
         BPL C31E16      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Chosen menu
         STA $25         ; Set submenu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32F07,X)  ; Handle choice

; Fork: Handle left
C31E16:  LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C31E22      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         JMP C32F61      ; Init Order menu

; Fork: Handle B
C31E22:  LDA $09         ; Pushing B?
         BPL C31E37      ; Exit if not
         STZ $0205       ; Clear field event
         JSR C30F14      ; Sound: Cursor
         JSR C31E38      ; Update field FX
fdexit:  LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
C31E37:  RTS

; Update field effects from gear (Charms, Sprint Shoes)
C31E38:  STZ $11DF       ; Clear effects
         LDX $00         ; Member slot: 1
C31E3D:  LDA $69,X       ; Actor in slot
         BMI C31E47      ; Skip if none
         PHX             ; Save slot
         JSL $C20006     ; Load gear FX
         PLX             ; Member slot
C31E47:  INX             ; Slot +1
         CPX #$0004      ; Done all 4?
         BNE C31E3D      ; Loop if not
         RTS

; 06: Handle single actor targeting in main menu
C31E4E:  JSR C33610      ; Redraw time
         LDA $09         ; Pushing B?
         BPL C31E63      ; Branch if not
         LDA #$05        ; Blinker: Off
         TRB $46         ; Actor cursor: Off
         LDA #$03        ; C3/1DFA
         STA $26         ; Next: Main menu
         JMP C30F14      ; Sound: Cursor

; Fork: Handle MT mode switch
C31E63:  BIT #$02        ; Pushing left?
         BEQ C31E85      ; Branch if not
         LDA $25         ; Selected menu
         CMP #$02        ; Equip?
         BEQ C31E73      ; Branch if so
         CMP #$03        ; Relic?
         BNE C31E85      ; Branch if not
C31E73:  JSR C30F0E      ; Sound: Cursor
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         LDA #$37        ; C3/1F1B
         STA $26         ; Next: Target all
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         JMP C30924      ; Create blinkers

; Fork: Handle A
C31E85:  LDA $08         ; Pushing A?
         BPL C31E37      ; Exit if not
         LDA $4B         ; Cursor slot
         STA $28         ; Set member slot
         JSR C31EB4      ; Can open menu?
         BCS C31EA8      ; Fail if not
         TDC             ; Clear A
         LDA $25         ; Menu to open
         TAX             ; Index it
         LDA.L C31EAF,X  ; Init command
         STA $27         ; Put in queue
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Fork: Inaccessible menu
C31EA8:  JMP C3C5C6      ; Buzzer + Mosaic

; Initialization commands for actor menus
C31EAF:  db $FF          ; Blank
         db $09          ; Skills
         db $35          ; Equip
         db $58          ; Relic
         db $0B          ; Status

; Determine if actor-related menu is accessible
C31EB4:  TDC             ; Clear A
         LDA $25         ; Menu to open
         DEC A           ; Skills?
         BEQ C31EEF      ; Branch if so
         DEC A           ; Equip?
         BEQ C31EC5      ; Branch if so
         DEC A           ; Relic?
         BEQ C31EDA      ; Branch if so

; Fork: Set to open menu
C31F19:  CLC             ; Mark success
         RTS

; Fork: Equip
C31EC5:  LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $00,X       ; Actor
         CMP #$0D        ; Umaro or guest?
         BCS C31F17      ; Fail if so
         BRA C31F02      ; Check if dead

; Fork: Relic
C31EDA:  LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $00,X       ; Actor
         CMP #$0E        ; Guest?
         BCS C31F17      ; Fail if so
         BRA C31F02      ; Check if dead

; Fork: Skills
C31EEF:  JSR C353FD      ; Set skill colors
         LDA #$24        ; Palette: Gray
         LDX #$0006      ; 1st: Dance
C31EF6:  CMP $79,X       ; Grayed skill?
         BNE C31F02      ; Branch if not
         DEX             ; Skill slot -1
         BPL C31EF6      ; Loop till Espers
         BRA C31F17      ; Play buzzer

; Fork: Check if dead
C31F02:  TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAY             ; Index it
         LDX $6D,Y       ; Actor's address
         LDA $14,X       ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BEQ C31F19      ; Allow if none

; Fork: Set to play buzzer
C31F17:  SEC             ; Mark failure
         RTS

; 37: Handle multitargeting in main menu
C31F1B:  JSR C33610      ; Redraw time
         LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C31F4B      ; Branch if not
         JSR C33033      ; Preload nav data
         JSR C30833      ; Queue cursor OAM
         LDY #C3305B     ; C3/305B
         JSR qanim0      ; Queue D-Pad fn
         JSR C3121B      ; Run anim queue
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$06        ; C3/1E4E
         STA $26         ; Next: ST actor
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
         JMP C30F14      ; Sound: Cursor

; Fork: Handle A
C31F4B:  LDA $08         ; Pushing A?
         BPL C31FBB      ; Exit if not
         STZ $26         ; Next: Fade-out
         LDA #$38        ; C3/1C98
         STA $27         ; Queue: Party gear
         JMP C30F1D      ; Sound: Click

; 08: Handle Item menu choice 1
C31F5D:  JSR desc_on     ; Description: On
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C31FBB      ; Exit if pushed
         JSR C384A9      ; Handle D-Pad
         JSR C38A72      ; Load description

; Fork: Handle B
C31F72:  LDA $09         ; Pushing B?
         BPL C31FA1      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         LDY $4F         ; Cursor position
         STY $022F       ; To cursor memory
         LDA $4A         ; Scroll position
         STA $0231       ; To cursor memory
         JSR C3852F      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C31F94      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C31F94:  JSR C38535      ; Relocate cursor
         LDA #$17        ; C3/2667
         STA $26         ; Next: Option list
         JSR C38B06      ; Blank item count
         JMP C30FA4      ; Queue its upload

; Fork: Handle A
C31FA1:  LDA $08         ; Pushing A?
         BPL C31FBB      ; Exit if not
         JSR C30F1D      ; Sound: Click
         LDA $4B         ; List slot
         STA $28         ; Set choice 1's
         LDA #$19        ; C3/27EC
         STA $26         ; Next: Choice 2
         JMP C32FBC      ; Create blinker

; Hi-fork: Pressed L on first page
C31FB6:  STZ $50         ; List row: 1
         STZ $4E         ; Cursor row: 1
         SEC             ; Mark L/R usage
C31FBB:  RTS

; Hi-fork: Pressed R on last page
C31FBC:  LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         STA $4E         ; Set cursor row
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $50         ; Set list row
         SEC             ; Mark L/R usage
         RTS

; Hi-fork: Do nothing
C31FC8:  CLC             ; Mark no L/R use
         RTS

; Handle L and R for scrollable list
C31FCA:  LDA $20         ; Scrolling now?
         BNE C31FC8      ; Exit if so
         LDA $0A         ; Semi-auto keys
         BIT #$10        ; Pushing R?
         BEQ C31FF9      ; Branch if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C31FBC      ; Branch if so
         LDA $5C         ; Scroll limit
         SEC             ; Prepare SBC
         SBC $4A         ; Get rows left
         CMP $5A         ; Full page below?
         BCC C31FE7      ; Branch if not
         LDA $5A         ; Rows per page
C31FE7:  STA $E0         ; Set shift qty
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         STA $4A         ; Set scroll pos
         LDA $50         ; List row
         CLC             ; Prepare ADC
         ADC $E0         ; Add shift qty
         STA $50         ; Save changes
         BRA C3201D      ; Redraw & Sound

; Fork: Handle L
C31FF9:  BIT #$20        ; Pushing L?
         BEQ C31FC8      ; Exit if not
         LDA $4A         ; On first page?
         BEQ C31FB6      ; Branch if so
         CMP $5A         ; Full page above?
         BCC C3200D      ; Branch if not
         LDA $5A         ; Rows per page
C3200D:  STA $E0         ; Set shift qty
         LDA $4A         ; Scroll position
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $4A         ; Save changes
         LDA $50         ; List row
         SEC             ; Prepare SBC
         SBC $E0         ; Sub shift qty
         STA $50         ; Save changes

; Fork: Redraw list, play sound effect
C3201D:  JSR C30F0E      ; Sound: Cursor
         TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JSR (C3202A,X)  ; Redraw list
         SEC             ; Mark L/R usage
         RTS

; Jump table for the above
C3202A:  dw C32036       ; Inventory
         dw C3203C       ; Magic
         dw C32042       ; Lore
         dw C32048       ; Rage
         dw C3204E       ; Esper
         dw C32054       ; Gear

; Redraw inventory for page swap (Item, Colosseum, Sell)
C32036:  JSR C38644      ; Load V-shift data
         JMP C38737      ; Draw inventory

; Redraw Magic list for page swap
C3203C:  JSR C354F3      ; Load V-shift data
         JMP C35659      ; Draw spell list

; Redraw Lore list for page swap
C32042:  JSR C354F3      ; Load V-shift data
         JMP C3590B      ; Draw Lore list

; Redraw Rage list for page swap
C32048:  JSR C354F3      ; Load V-shift data
         JMP C35A02      ; Draw Rage list

; Redraw Esper list for page swap
C3204E:  JSR C354F3      ; Load V-shift data
         JMP C35AC6      ; Draw esper list

; Redraw gear list for page swap (Equip, Relic)
C32054:  JSR C39D0F      ; Load V-shift data
         JMP C3A49B      ; Draw item list

; 0A: Sustain Skills menu
C3205A:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C35219      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C32075      ; Branch if not
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Handle A
C32075:  LDA $08         ; Pushing A?
         BPL C32082      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5E         ; Set return loc
         BRA C320EA      ; Invoke submenu

; Fork: Handle L and R, prepare for menu reset
C32082:  LDA #$09        ; Init cmd: C3/1BC1

; Handle member switching with L or R (excludes Status menu)
C32088:  STA $E0         ; Set init command
         LDX #$0001      ; Swap order: R
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE .go         ; Branch if so
         BIT #$20        ; Pushing L?
         BEQ C320E9      ; Exit if not
         LDX #$FFFF      ; Swap order: L
.go      STX $F3         ; Set swap order
         LDA $25         ; Submenu
         CMP #$03        ; Relic?
         BNE C3209F      ; Branch if not
         JSR C3A6F9      ; Handle Reequip
         BCC C3209F      ; If not triggered
         JMP C30F0E      ; Sound: Cursor

; Fork: Switch to next or preceding member
C3209F:  TDC             ; Clear A
         LDA $28         ; Current member
         CLC             ; Prepare ADC
         ADC $F3         ; Go L or R
         AND #$03        ; Wrap if needed
         STA $28         ; Save changes
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C3209F      ; Skip if so
         JSR C31EB4      ; Can access menu?
         BCS C3209F      ; Skip if not
         LDA $E0         ; Init command
         STA $26         ; Set menu mode
         JMP C30F0E      ; Sound: Cursor
C320E9:  RTS

; Initialize selected Skills submenu if accessible
C320EA:  TDC             ; Clear A
         LDA $4B         ; Chosen menu
         TAX             ; Index it
         LDA $79,X       ; Name's color
         CMP #$20        ; User's color?
         BNE C320FE      ; Fail if not
         JSR C30F1D      ; Sound: Click
         STZ $4A         ; List scroll: 0
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         TXA             ; Chosen menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32105,X)  ; Invoke menu

; Fork: Play buzzer
C320FE:  JMP C3C5C6      ; Buzzer + Mosaic

; Jump table for the above
C32105:  dw C32113       ; Espers
         dw C3217C       ; Magic
         dw C3214E       ; SwdTech
         dw C32165       ; Blitz
         dw C321CE       ; Lore
         dw C32206       ; Rage
         dw C3223E       ; Dance

; Initialize Espers menu
C32113:  JSR C35AAC      ; Draw espers, etc.
         JSR C32F86      ; Create blinker
C3211_:  LDA #$60        ; Y: 96
         LDY #$1333      ; V-Speed: 19.2 px
         JSR C309A4      ; Create scrollbar
         LDA #$05        ; Top row: Carb.'s
         STA $5C         ; Set scroll limit
         LDX #$0209      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 2
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$1E        ; C3/2946
         STA $26         ; Next: Sustain menu
         JSR C352CD      ; Load navig data
         JMP C352D6      ; Relocate cursor

; Initialize SwdTech menu
C3214E:  JSR C352A7      ; Load navig data
         JSR C352B0      ; Relocate cursor
         LDA #$3E        ; C3/29F8
         STA $26         ; Next: Sustain menu
         JMP C359B0      ; Draw techs, etc.

; Initialize Blitz menu
C32165:  JSR C352A7      ; Load navig data
         JSR C352B0      ; Relocate cursor
         LDA #$33        ; C3/29E1
         STA $26         ; Next: Sustain menu
         JMP C35C2D      ; Draw inputs, etc.

; Initialize Magic menu
C3217C:  LDA #$1A        ; C3/2855
         STA $26         ; Next: Sustain menu
         JSR C32190      ; Create scrollbar
         JSR C321A8      ; Load nav data, etc.
         JSR C321B8      ; Draw spells, etc.
         JMP C30FB8      ; Queue BG3 upload

; Create scrollbar for Magic menu
C32190:  LDA #$60        ; Y: 96
         LDY #$08BA      ; V-Speed: 8.73 px
         JMP C309A4      ; Queue OAM fn

; Load navigation data for Magic menu; position cursor
C321A8:  JSR C35245      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C321B5      ; Branch if not
         JSR C30E75      ; Restore cursor
C321B5:  JMP C3524E      ; Relocate cursor

; Switch to Magic menu, create portrait, draw spells and "MP.."
C321B8:  LDA #$0B        ; Top row: Quake's
         STA $5C         ; Set scroll limit
         LDX #$0309      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 3
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         JSR C3543F      ; Draw spells, etc.
         JMP C35895      ; Draw MP cost

; Initialize Lore menu
C321CE:  LDA #$60        ; Y: 96
         LDY #$2000      ; V-Speed: 32 px
         JSR C309A4      ; Create scrollbar
         JSR C352CD      ; Load navig data
         JSR C352D6      ; Relocate cursor
         LDA #$03        ; Top row: Big Guard
         STA $5C         ; Set scroll limit
         LDX #$0209      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 2
         LDA #$1B        ; C3/28FD
         STA $26         ; Next: Sustain menu
         JMP C358C8      ; Draw lores, etc.

; Initialize Rage menu
C32206:  LDA #$60        ; Y: 96
         LDY #$00CE      ; V-Speed: 0.8 px
         JSR C309A4      ; Create scrollbar
         LDY #C35314     ; C3/5314
         JSR C30681      ; Load navig data
         JSR C3530E      ; Relocate cursor
         LDA #$77        ; Top row: Mandrake
         STA $5C         ; Set scroll limit
         LDX #$0209      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 2
         LDA #$1D        ; C3/292D
         STA $26         ; Next: Sustain menu
         JMP C359EC      ; Draw rages, etc.

; Initialize Dance menu
C3223E:  JSR C352A7      ; Load navig data
         JSR C352B0      ; Relocate cursor
         LDA #$1C        ; C3/291D
         STA $26         ; Next: Sustain menu
         JMP C35DD1      ; Draw dances, etc.

; 0C: Sustain Status menu
C32255:  JSR C30FA4      ; Set to redraw cmds
         LDX #$0001      ; Swap order: R
         LDA $08         ; No-autofire keys
         BIT #$10        ; Pushing R?
         BNE .go         ; Branch if so
         BIT #$20        ; Pushing L?
         BEQ C322A4      ; Branch if not
         LDX #$FFFF      ; Swap order: L
.go      STX $E0         ; Set swap order
         LDA $28         ; Member slot
         PHA             ; Set former slot

; Fork: Switch to next or preceding member
C32262:  TDC             ; Clear A
         LDA $28         ; Member slot
         CLC             ; Prepare ADC
         ADC $E0         ; Go L or R
         AND #$03        ; Wrap if needed
         STA $28         ; Save changes
         TAX             ; Index slot
         LDA $69,X       ; Nobody there?
         BMI C32262      ; Skip slot if so
         PLA             ; Former member
         CMP $79         ; Matches new one?
         BEQ C32278      ; Skip sound if so
         JSR C30F0E      ; Sound: Cursor
C32278:  JSR C31CC3      ; Init cursor data
         JMP C363E0      ; Swap actor info

; Fork: Handle B
C322A4:  LDA $09         ; Pushing B?
         BPL C322B4      ; Branch if not
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Handle Gogo
C322B4:  JSR gogo1       ; Actor = Gogo?
         BNE C32313      ; Exit if not
         JSR C337CD      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C32313      ; Exit if not
         JSR C30F1D      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         JSR C32D9E      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         ADC $E7         ; Add cursor slot
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $16,X       ; Chosen command
         CMP #$12        ; Mimic?
         BEQ C32313      ; Exit if so
         JSR C32FA1      ; Create blinker
         LDA $4E         ; Cursor row
         STA $64         ; Set altered slot
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$6A        ; C3/69F0
         STA $27         ; Queue: Shifted menu
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Shift screen
         LDY #C36A5B     ; C3/6A5B
         JSR C30681      ; Load navig data
         LDA $7E9D89     ; Command list size
         STA $54         ; Set number of rows
         JMP C36A55      ; Relocate cursor
C32313:  RTS

; 0E: Sustain Config menu
C32325:  JSR C30F54      ; Queue list upload
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C32340      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$09        ; On Controller?
         BNE C32340      ; Branch if not
         LDA #$50        ; C3/3AD4
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle upward scrolling
C32340:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3235A      ; Branch if not
         LDA $4E         ; On top row?
         BNE C3235A      ; Branch if not
         LDA $4A         ; On first page?
         BEQ C3235A      ; Branch if so
         LDA #$51        ; C3/3AF5
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle B and D-Pad
C3235A:  LDA $4A         ; On first page?
         BEQ C32363      ; Branch if so
         JSR C33955      ; Handle P2 D-Pad
         BRA C32366      ; Skip a line
C32363:  JSR C3392D      ; Handle P1 D-Pad
C32366:  LDA $09         ; Pushing B?
         BPL C32376      ; Branch if not
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Handle left and right
C32376:  LDA $0B         ; Semi-auto keys
         BIT #$03        ; Using left/right?
         BEQ C32385      ; Branch if not
         JMP C33E34      ; Change settings

; Fork: Handle A
C32385:  LDA $08         ; Pushing A?
         BMI C32391      ; Branch if so

; Fork: Handle L and R
C3238E:  JMP C3245F      ; Handle L and R

; Fork: Handle clicked option
C32391:  LDA $4E         ; Cursor row
         STA $5F         ; Set return row
         LDA $4A         ; On page 2?
         BNE C323A2      ; Branch if so
         LDA $4B         ; Cursor slot
         CMP #$03        ; On Cmd.Set?
         BEQ C323CA      ; Branch if so
         CMP #$08        ; On Btn.Set?
         BEQ C323DB      ; Branch if so
         BCS C323EC      ; If Controller
         RTS

; Fork: Handle click on page 2
C323A2:  LDA $4B         ; Cursor slot
         CMP #$02        ; In color area?
         BCS C323FB      ; Branch if so
         RTS

; Handle click on "Short" option
C323CA:  LDA $1D4D       ; Short cmd set?
         BPL C3245E      ; Exit if not
         LDA #$47        ; C3/43A3
         STA $27         ; Queue cmd menu
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Handle click on "Custom" option
C323DB:  LDA $1D54       ; Game options
         ASL A           ; Custom buttons?
         BPL C3245E      ; Exit if not
         LDA #$49        ; C3/478E
         STA $27         ; Queue key menu
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Handle click on "Multiple" option
C323EC:  LDA $1D54       ; Multiplayer mode?
         BPL C3245E      ; Exit if not
         LDA #$4B        ; C3/47E2
         STA $27         ; Queue joypad menu
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Handle color resetting in options
C323FB:  JSR C30F1D      ; Sound: Click
         LDA $1D54       ; Game options
         AND #$38        ; Get viewed color
         BEQ C3240E      ; Branch if font
         JSR C3241A      ; Reset skin colors
         JSR C33B5B      ; Refresh skin
         JMP C342A4      ; Redraw RGB info

; Fork: Reset font color
C3240E:  LDY #$7FFF      ; Color: White
         STY $1D55       ; Put in options
         JSR C340B9      ; Put in palettes
         JMP C342A4      ; Redraw RGB info

; Reset skin palette
C3241A:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         PHA             ; Memorize it
         LDY #$0020      ; ROM data size
         JSR mul16       ; Skin x size
         PLA             ; Wallpaper
         PHX             ; Save ROM index
         LDY #$000E      ; RAM data size
         JSR mul16       ; Skin x size

; Fork: Load skin palette
C3243C:  LDY #$312B      ; 7E/312B
         STY $2181       ; Set WRAM LBs
         TXY             ; RAM index
         PLX             ; ROM index
         SEP #$20        ; 8-bit A
         LDA #$0E        ; Colors: 7
C3244E:  PHA             ; Save counter
         LDA $ED1C02,X   ; Color data
         STA $1D57,Y     ; Put in options
         STA $2180       ; Put in palette
         INX             ; ROM index +1
         INY             ; RAM index +1
         PLA             ; Bytes left
         DEC A           ; One less left
         BNE C3244E      ; Loop till last
C3245E:  RTS

; Handle L and R in Config menu
C3245F:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BEQ C3245E      ; Exit if not
         JSR C30F0E      ; Sound: Cursor
         LDA $4A         ; On first page?
         BNE C32479      ; Branch if not
         INC $4A         ; Page: 2nd
         JMP C33ABE      ; Switch screens

; Fork: On page 2
C32479:  STZ $4A         ; Page: 1st
         JMP C33AC9      ; Switch screens

; 0F: Handle Order menu choice 1
C3247F:  JSR C33610      ; Redraw time
         JSR C370FB      ; Set SRAM party
         LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C324AA      ; Branch if not
C32491:  LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$03        ; C3/1DFA
         STA $27         ; Queue: Main menu
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Pan screen
         JMP C30F14      ; Sound: Cursor

; Fork: Handle A
C324AA:  LDA $08         ; Pushing A?
         BPL C3245E      ; Exit if not
         LDA $4B         ; Selected slot
         STA $28         ; Set choice 1
         LDA #$10        ; C3/24C6
         STA $26         ; Next: Choice 2
         JSR C32FBC      ; Create blinker
         JSR C3304C      ; Unlock all slots
         JMP C30F1D      ; Sound: Click

; 10: Handle Order menu choice 2
C324C6:  JSR C33610      ; Redraw time
         LDA $09         ; Pushing B?
         BPL C324E2      ; Branch if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$0F        ; C3/247F
         STA $26         ; Next: Choice 1
         JSR C33033      ; Lock empty slots
         LDA $28         ; Old cursor row
         STA $4E         ; Set as current
         JMP C30F14      ; Sound: Cursor

; Fork: Change row
C324E2:  LDA $08         ; Pushing A?
         BPL C3251B      ; Exit if not
         JSR C30F1D      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C32504      ; Swap if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$12        ; C3/25AA
         STA $26         ; Next: Wait
         JSR C32EAB      ; Set row, scroll
         LDY #$000C      ; Frames: 12
         STY $20         ; Set wait timer
         JMP C33033      ; Lock empty slots

; Fork: Switch members
C32504:  LDA #$10        ; Cursor: Freeze
         TRB $46         ; Set menu flag
         LDA #$0C        ; Cursor: Blank
         TRB $45         ; Unhide chars: N
         JSR C3364A      ; Queue swap anim
         LDA #$18        ; Frames: 24
         STA $22         ; Set anim timer
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$11        ; C3/251C
         STA $26         ; Next: Sustain swap
C3251B:  RTS

; 11: Switch members in Order menu
C3251C:  JSR C33610      ; Redraw time
         LDA $22         ; Timer expired?
         BEQ C32553      ; Finalize if so
         CMP #$0C        ; Unhide point?
         BNE C32560      ; Exit if not
         JSR C3256B      ; Swap battle pads
         JSR C32E6C      ; Swap actor info
         JSR C32561      ; Clear icons/faces
         JSR C371A9      ; Erase party info
         JSR C3322E      ; Redraw party info
         JSR C30E25      ; Swap saved cursors
         JSR C30F68      ; Queue stats upload
         JSR C33033      ; Lock empty slots
         JSR C3121B      ; Run anim queue
         JSR C313D3      ; Refresh screen
         LDA #$08        ; Unhide members: Y
         TSB $45         ; Set menu flag
         RTS

; Fork: Restore control
C32553:  LDA #$0F        ; C3/247F
         STA $26         ; Next: Choice 1
         LDA #$10        ; Cursor: Unfreeze
         TSB $46         ; Set menu flag
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
C32560:  RTS

; Delete all portraits and status icons
C32561:  JSR C32ED7      ; Portraits: Erase
         LDA #$01        ; Icons: Delete
         TRB $47         ; Set menu flag
         JMP C3121B      ; Run anim queue

; Swap assigned joypad for switched members
C3256B:  TDC             ; Clear A
         TAX             ; Member slot: 1
         STX $E0         ; Char 1+2: Pad 1
         STX $E2         ; Char 3+4: Pad 1
         LDA $1D4F       ; Game options
         CLC             ; Prepare ROR
C32575:  ROR A           ; Member's joypad
         BCC C3257A      ; Skip if Pad 1
         INC $E0,X       ; Assign Pad 2
C3257A:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C32575      ; Loop if not
         TDC             ; Clear A
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E0,X       ; Member B's pad
         PHA             ; Memorize it
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $E0,X       ; Member A's pad
         STA $E6         ; Memorize it
         PLA             ; Member B's pad
         STA $E0,X       ; Set as A's
         LDA $4B         ; Chosen slot B
         TAX             ; Index it
         LDA $E6         ; Member A's pad
         STA $E0,X       ; Set as B's
         LDA $E3         ; Member 4's pad
         ASL A           ; Put in bit 1
         ADC $E2         ; Add member 3's
         ASL A           ; Put in bit 1-2
         ADC $E1         ; Add member 2's
         ASL A           ; Put in bit 1-3
         ADC $E0         ; Add member 1's
         STA $1D4F       ; Update options
         RTS

; 12: Wait while member changes row
C325AA:  LDY $20         ; Timer expired?
         BNE C325B2      ; Exit if not
         LDA #$0F        ; C3/247F
         STA $26         ; Next: Choice 1
C325B2:  RTS

; 14: Sustain Save menu
C325B3:  LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C3196C      ; Refresh actors
         JSR C31613      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C325D0      ; Branch if not
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         LDA #$53        ; C3/1A64
         STA $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Handle A
C325D0:  LDA $08         ; Pushing A?
         BPL C325B2      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BNE C325F3      ; Branch if not
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C32652      ; Save game
         LDA #$13        ; Menu init cmd
         STA $27         ; Queue Save menu
         LDA #$53        ; C3/1A64
         STA $26         ; Next: Fade-out
         JMP C30F24      ; Sound: Save

; Fork: Invoke confirmation menu
C325F3:  JSR C31915      ; Back up SRAM data
         LDA $4B         ; Cursor slot
         INC A           ; Now 1-3
         STA $66         ; Set save slot
         JSR C315CF      ; Load save file
         JSR C37087      ; Move party info
         JSR C370FB      ; Set SRAM party
         LDA #$15        ; C3/1D49
         STA $27         ; Queue submenu
         LDA #$53        ; C3/1A64
         STA $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; 16: Sustain save confirmation
C32610:  JSR C31643      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BMI C32635      ; Abort if so
         LDA $08         ; Pushing A?
         BPL C32651      ; Exit if not
         LDA $4B         ; Chose "No"?
         BNE C3263A      ; Abort if so
         LDA $66         ; Save slot
         STA $021F       ; Link to game
         JSR C32652      ; Save game
         LDA #$13        ; C3/1D06
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         JMP C30F24      ; Sound: Save

; Fork: Pushing B
C32635:  JSR C30F14      ; Sound: Cursor
         BRA C3263D      ; Skip a line

; Fork: Chose "No"
C3263A:  JSR C30F1D      ; Sound: Click
C3263D:  JSR C3192A      ; Restore SRAM
         JSR C37087      ; And party info
         JSR C370FB      ; Set SRAM party
         LDA #$13        ; C3/1D06
         STA $27         ; Queue Save menu
         STZ $26         ; Next: Fade-out
         LDA $66         ; File number
         STA $0224       ; Set last viewed
C32651:  RTS

; Restore SRAM block and record game data
C32652:  JSR C3192A      ; Restore SRAM
         JSR C37087      ; And party info
         JSR C370FB      ; Set SRAM party
         REP #$20        ; 16-bit A
         INC $1DC7       ; Save count +1
         SEP #$20        ; 8-bit A
         LDA $66         ; File number
         JMP C31588      ; Save game data

; 17: Handle Item menu options
C32667:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30F68      ; Queue stock upload
         JSR C3853B      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C32684      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
C32684:  LDA $08         ; Pushing A?
         BPL C32651      ; Exit if not
         JSR C30F1D      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C32699,X)  ; Handle option

; Jump table for the above
C32699:  dw C3269F       ; USE
         dw C326EF       ; ARRANGE
         dw C32701       ; RARE

; Handle "USE" selection in Item menu
C3269F:  JSR C384A3      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C326AE      ; Branch if not
         JSR C30E17      ; Restore cursor
         BRA C326BE      ; Skip cursor reset
C326AE:  LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $0231       ; Old scroll pos
         STA $4A         ; Set as current
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
C326BE:  JSR C384AC      ; Relocate cursor
         JSR C3CB59      ; Draw list; bar
         JSR C38A72      ; Desc; item count
         JSR C30FA4      ; Queue BG3 upload
         JSR C313D3      ; Refresh screen
         JSR C38C9B      ; Next: Choice 1
         LDY #C3B151     ; C3/B151
         JMP qanim0      ; Queue desc update

; Handle "ARRANGE" selection in Item menu
C326EF:  JSR C371A9      ; Hide inventory
         JSR C3272B      ; Move inventory
         JSR C32753      ; Sort inventory
         JSR C38737      ; Redraw inventory
         JSR C3852F      ; Load navig data
         JMP C31F94      ; Move cursor, etc.

; Initialize rare item menu
C32701:  LDY #C384EE     ; C3/84EE
         JSR C30681      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C32710      ; Branch if not
         LDY $0232       ; Former position
         STY $4D         ; Set as current
C32710:  JSR C384E8      ; Relocate cursor
         JSR C38B0C      ; Draw item list
         JSR C31BFF      ; Queue desc anim
         JSR C38ABA      ; Get desc/draw count
         JSR C30FA4      ; Queue count upload
         JSR C313D3      ; Refresh screen
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$18        ; C3/27B4
         STA $26         ; Next: Sustain menu
         RTS

; Relocate inventory for sorting, delete original
C3272B:  LDX #$00FF      ; Item slot: 256
C3272D:  LDA $1869,X     ; Item in slot
         STA $7EAA8D,X   ; Put in buffer
         LDA #$FF        ; Empty item
         STA $1869,X     ; Clear original
         LDA $1969,X     ; Item quantity
         STA $7EAB8D,X   ; Put in buffer
         STZ $1969,X     ; Clear original
         DEX             ; Item slot -1
         BPL C3272D      ; Loop till < 0
         RTS

; Sort inventory based on item icons
C32753:  TDC             ; Clear A
         TAY             ; Item slot: 1
         TAX             ; Icon index: 0
C32756:  LDA.L C32768,X  ; Item icon
         PHX             ; Save index
         STA $E0         ; Set class
         JSR C32779      ; Get such items
         PLX             ; Icon index
         INX             ; Index +1
         CPX #$0011      ; Done 17 icons?
         BNE C32756      ; Loop if not
         RTS

; Copy all items with given icon from buffer to inventory
C32779:  TDC             ; Clear A
         TAX             ; Buffer slot: 1
C3277B:  PHX             ; Save buffer slot
         LDA $7EAA8D,X   ; Item in slot
         CMP #$FF        ; None?
         BEQ C327AC      ; Skip if so
         XBA             ; Put in B
         LDA.B #!itm_ns  ; Name data size
         JSR mul8        ; Item x size
         TAX             ; Index product
         LDA.L !itm_np,X ; Item icon
         CMP $E0         ; Sought type?
         BNE C327AC      ; Skip if not
         PLX             ; Buffer slot
         LDA $7EAA8D,X   ; Item in slot
         STA $1869,Y     ; Put in stock
         LDA $7EAB8D,X   ; Item quantity
         STA $1969,Y     ; Put in stock
         INY             ; Stock slot +1
         BRA C327AD      ; Skip a line
C327AC:  PLX             ; Buffer slot
C327AD:  INX             ; Buffer slot +1
         CPX #$0100      ; Done all 256?
         BNE C3277B      ; Loop if not
C327B3:  RTS

; 18: Sustain rare item menu
C327B4:  JSR desc_on     ; Description: On
         JSR C30F68      ; Queue list upload
         JSR C384E5      ; Handle D-Pad
         JSR C38ABA      ; Get desc/draw count
         LDA $09         ; Pushing B?
         BPL C327B3      ; Exit if not
         JSR C30F14      ; Sound: Cursor
         LDA #$17        ; C3/2667
         STA $26         ; Next: Option list
         LDY $4D         ; Cursor position
         STY $0232       ; To cursor memory
         JSR C3852F      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C327E2      ; Branch if not
         LDY $0234       ; Former position
         STY $4D         ; Set as current
C327E2:  JSR C38535      ; Relocate cursor
         JSR C38B06      ; Blank item count
         JMP C30FA4      ; Queue its upload

; 19: Handle Item menu choice 2
C327EC:  JSR C30F68      ; Queue list upload
         JSR C384A9      ; Handle D-Pad
         JSR C38A72      ; Load description
         LDA $09         ; Pushing B?
         BPL C32807      ; Branch if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JSR C38C9B      ; Next: Choice 1
         JMP C30F14      ; Sound: Cursor

; Fork: Handle A
C32807:  LDA $08         ; Pushing A?
         BPL C327B3      ; Exit if not
         JSR C30F1D      ; Sound: Click
         LDA $28         ; First selection
         CMP $4B         ; Matches second?
         BNE C3281D      ; Swap them if not
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JMP C38C22      ; Handle item

; Fork: Switch items
C3281D:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         JSR C38C9B      ; Next: Choice 1
         TDC             ; Clear A
         LDA $28         ; Slot A
         TAY             ; Index it
         LDA $1969,Y     ; Quantity A
         PHA             ; Save it
         LDA $1869,Y     ; Item A
         PHA             ; Save it
         LDA $4B         ; Slot B
         TAX             ; Index it
         LDA $1869,X     ; Item B
         STA $1869,Y     ; Replace A
         PLA             ; Item A
         STA $1869,X     ; Replace B
         LDA $1969,X     ; Quantity B
         STA $1969,Y     ; Replace A
         PLA             ; Quantity A
         STA $1969,X     ; Replace B
         JMP C38737      ; Redraw list

; 1A: Sustain Magic menu
C32855:  JSR desc_on     ; Description: On
         LDA #$01        ; List type: Magic
         STA $2A         ; Set redraw mode
         JSR C30F68      ; Queue list upload
         LDA $021E       ; Frame counter
         LSR A           ; Even value?
         BCC C3286B      ; Favor desc if so
         JSR C30FE0      ; Queue cost upload
         BRA C3286E      ; Skip a line
C3286B:  JSR C3B301      ; Queue desc upload
C3286E:  JSR C31FCA      ; Handle L and R
         BCS C328C7      ; Exit if pushed
         JSR C3524B      ; Handle D-Pad
         JSR C35D42      ; Load description
         JSR C35895      ; Draw MP cost

; Fork: Handle Y
C3287C:  LDA $09         ; No-autofire keys
         ASL A           ; Pushing Y?
         BPL C32895      ; Branch if not
         JSR C30F1D      ; Sound: Click
         LDA $9E         ; MP display switch
         EOR #$FF        ; Toggle it
         STA $9E         ; Save changes
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C355EB      ; Build spell list
         JMP C35659      ; Draw spell list

; Fork: Handle A
C32895:  LDA $08         ; Pushing A?
         BPL C328C8      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Spell slot
         TAX             ; Index it
         LDA $7E9E09,X   ; Spell palette
         CMP #$20        ; User's color?
         BNE C328D5      ; Fail if not
         JSR C30F1D      ; Sound: Click
         LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA $4B         ; Cursor slot
         STA $99         ; Set spell slot
         JSR C32DAE      ; Spell
         CMP #$2A        ; Warp?
         BEQ C328E7      ; Branch if so
         LDA #$3A        ; C3/2B00
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
C328C7:  RTS

; Fork: Handle B
C328C8:  LDA $09         ; Pushing B?
         BPL C328C7      ; Exit if not
         JSR C30F68      ; Queue BG1 upload
         JMP C32A40      ; Exit submenu

; Fork: Unusable spell
C328D5:  JMP C3C5C6      ; Buzzer + Mosaic

; Fork: Warp
C328E7:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C328D5      ; Fail if not
         LDA #$03        ; Event: Warp
C328F0:  STA $0205       ; Set aftereffect
         JSR C32D85      ; Lower caster's MP
         JMP fdexit      ; Queue menu exit

; 1B: Sustain Lore menu
C328FD:  JSR desc_on     ; Description: On
         LDA #$02        ; List type: Lores
         STA $2A         ; Set redraw mode
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C328C7      ; Exit if pushed
         JSR C352D3      ; Handle D-Pad
         JSR C35D48      ; Load description
         LDA $09         ; Pushing B?
         BPL C328C7      ; Exit if not
         JMP C32A40      ; Leave submenu

; 1C: Sustain Dance menu
C3291D:  JSR C30F68      ; Queue list upload
         JSR C352AD      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C3297A      ; Exit if not
         JMP C32A40      ; Leave submenu

; 1D: Sustain Rage menu
C3292D:  LDA #$03        ; List type: Rages
         STA $2A         ; Set redraw mode
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C3297A      ; Exit if pushed
         JSR C3530B      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BPL C3297A      ; Exit if not
         JMP C32A40      ; Leave submenu

; 1E: Handle esper selection
C32946:  JSR desc_on     ; Description: On
         LDA #$04        ; List type: Espers
         STA $2A         ; Set redraw mode
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C3297A      ; Exit if pushed
         JSR C352D3      ; Handle D-Pad
         JSR C35D3C      ; Load description
         LDA $08         ; Pushing A?
         BPL C3298E      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JSR C3CF1D      ; Chosen esper
         CMP #$FF        ; Empty slot?
         BEQ C3297B      ; Unequip if so
         STA $99         ; Memorize esper
         JSR C35EEC      ; Init submenu
         LDA #$4D        ; C3/5F23
         STA $26         ; Next: Data menu
C3297A:  RTS

; Fork: Unequip esper
C3297B: ;LDA #$FF        ; Value for empty
         STA $E0         ; Set esper to equip
         JSR C3299C      ; Clear esper held
         JSR C35AC6      ; Redraw esper list
         JSR C30F7C      ; Queue stats upload
         JSR C313D3      ; Refresh held esper
         JMP C30F68      ; Queue list upload

; Fork: Handle B
C3298E:  LDA $09         ; Pushing B?
         BPL C3297A      ; Exit if not
         LDA #$08        ; Blinker: Off
         TRB $46         ; Set menu flag
         BRA C32A40      ; Leave submenu

; Equip and draw selected esper
C3299C:  JSR C32D9E      ; Actor's address
         LDA $E0         ; Chosen esper
         STA $001E,Y     ; Assign to actor
         JMP C355D7      ; Draw it by actor

; 34: Wait while showing who holds esper
C329AD:  LDY $20         ; Timer expired?
         BNE C3297A      ; Exit if not
         LDY #$40DD      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDY #$0012      ; Spaces: 18
         JSR spacedr     ; Blank message
         JMP C35F68      ; Exit submenu

; 39: Sustain party gear overview
C329D0:  LDA $09         ; Pushing B?
         BPL C329F7      ; Exit if not
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; 33: Sustain Blitz menu
C329E1:  JSR desc_on     ; Description: On
         JSR C30F68      ; Queue list upload
         JSR C352AD      ; Handle D-Pad
         JSR C35D72      ; Load description
         LDA $09         ; Pushing B?
         BMI C32A40      ; Return if so
C329F7:  RTS

; 3E: Sustain SwdTech menu
C329F8:  JSR desc_on     ; Description: On
         JSR C30F68      ; Queue list upload
         JSR C352AD      ; Handle D-Pad
         JSR C35D5D      ; Load description
         LDA $08         ; Pushing A?
         BPL C32A2A      ; Branch if not
         JSR C3CF1D      ; SwdTech in slot
         BMI C32A24      ; Fail if none
         STA $0206       ; Set chosen tech
         LDA #$FF        ; SwdTech renaming
         STA $0205       ; Set next menu
         JMP fdexit      ; Queue menu exit

; Fork: Invalid selection
C32A24:  JSR C3C5C6      ; Buzzer + Mosaic

; Fork: Handle B
C32A2A:  LDA $09         ; Pushing B?
         BPL C329F7      ; Exit if not
         JSR C371D5      ; Clear BG3 map B
         JSR C3AFC5      ; Build desc map
         JSR C30FB8      ; Queue its upload
         JSR C313D3      ; Upload it now

; Return to Skills menu
C32A40:  JSR C30F14      ; Sound: Cursor
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         STY $3D         ; Set BG3 X-Pos
         LDA #$0A        ; C3/205A
         STA $26         ; Next: Skills menu
         JSR C353E7      ; Erase spell list
         JSR C35213      ; Load navig data
         LDA $5E         ; Old cursor row
         STA $4E         ; Set as current
         JSR C3521C      ; Relocate cursor
         JMP C35E66      ; Remove portrait

; 21: Sustain Load menu
C32A5D:  LDA $4B         ; Cursor slot
         STA $66         ; Set save slot
         JSR C3196C      ; Refresh actors
         JSR C31627      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C329F7      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; On new game?
         BEQ C32AA2      ; Branch if so
         STA $66         ; Set save slot
         DEC A           ; Now 0-2
         ASL A           ; Double it
         TAX             ; Index it
         LDY $91,X       ; Blank file?
         BEQ C32A9B      ; Fail if so
         JSR C31915      ; Back up SRAM data
         LDA $66         ; Chosen save file
         STA $0224       ; Set last viewed
         JSR C315CF      ; Load save file
         JSR C37087      ; Move party info
         JSR C370FB      ; Set SRAM party
         JSR C315FE      ; Move timer data
         LDA #$22        ; C3/1DB7
         STA $27         ; Queue confirm menu
         LDA #$53        ; C3/1A64
         STA $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Fork: Blank file
C32A9B:  JMP C3C5C6      ; Buzzer + Mosaic

; Fork: New game
C32AA2:  JSR C32ABC      ; Reset play time
         LDA #$01        ; Save file: 1st
         STA $0224       ; Set last viewed
         STZ $021F       ; Game's file: None
         STZ $0205       ; Set new game mode
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$53        ; C3/1A64
         STA $26         ; Next: Fade-out
C32ABB:  JMP C30F1D      ; Sound: Click

; Reset play time
C32ABC:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $021B       ; Zero hours, mins
         STY $021D       ; Zero secs, frames
         RTS

; 23: Sustain load confirmation
C32AC5:  JSR C31643      ; Handle D-Pad
         LDA $09         ; Pushing B?
         BMI C32AF3      ; Abort if so
         LDA $08         ; Pushing A?
         BPL C32AFF      ; Exit if not
         JSR C30F1D      ; Sound: Click
         LDA $4B         ; Chose "No"?
         BNE C32AF6      ; Abort if so
         LDY $1863       ; File's hrs, mins
         STY $021B       ; Set as current
         LDA $1865       ; File's seconds
         STA $021D       ; Set as current
         LDA $66         ; Loaded file
         STA $021F       ; Link to game
         JMP fdexit      ; Queue menu exit

; Fork: Chose "No"
C32AF3:  JSR C30F14      ; Sound: Cursor
C32AF6:  JSR C3192A      ; Restore SRAM
         LDA #$20        ; C3/1D69
         STA $27         ; Queue Load menu
         STZ $26         ; Next: Fade-out
C32AFF:  RTS

; 3A: Initialize spell usage menu
C32B00:  LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         JSR C32B11      ; Init variables
         JSR C35E71      ; Draw menu
         JSR C30833      ; Queue cursor OAM
         LDA #$3B        ; Queue: Sustain menu
         BRA C32B40      ; Next: Fade-in

; Initialize variables for spell or item usage menu
C32B11:  JSR C335F7      ; Reset/Stop stuff
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue Win1 HDMA
         JSR C30FF4      ; Null VRAM ptr
         JSR C37076      ; Reset BGs' X/Y
         JSR C31C0E      ; Load portraits
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$C0        ; Channels: 6, 7
         TRB $43         ; Halt HDMA 6+7
         LDY #$0002      ; Y: 2
         STY $37         ; Set BG1 Y-Pos
         JSR C33033      ; Preload nav data
         LDY #C3305B     ; C3/305B
         JMP qanim0      ; Queue D-Pad fn

; Set queued menu command, trigger fade-in
C32B40:  STA $27         ; Set queued cmd
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 3B: Handle single-target spell
C32B49:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C32B61      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$03        ; Using left/right?
         BEQ C32B8E      ; Branch if not
C32B61:  JSR C30F0E      ; Sound: Cursor
         JSR C32DAE      ; Spell
         JSR C357C4      ; Compute index
         LDA $C46AC0,X   ; Spell properties
         AND #$20        ; Can multi-target?
         BEQ C32B8E      ; Branch if not
         LDA $4E         ; Cursor row
         STA $5F         ; Save for revert
         LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         LDA #$3D        ; C3/2E13
         STA $26         ; Next: Target all
         JMP C30924      ; Create blinkers

; Fork: Handle A
C32B8E:  LDA $08         ; Pushing A?
         BMI C32BA7      ; Branch if so

; Fork: Handle B
C32B97:  LDA $09         ; Pushing B?
         BPL C32BA6      ; Exit if not
         LDA #$3C        ; C3/2DB7
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor
C32BA6:  RTS

; Fork: Handle spell usage on single target
C32BA7:  STZ $9C         ; Halve HP gain: N
         JSR C32D67      ; Get LV, Mag.Pwr
         JSR C32DA6      ; Target's address
         JSR C32CAF      ; Valid target?
         BCC C32BCD      ; Fail if not
         JSR C32D85      ; Lower caster's MP
         JSR C30F50      ; Play heal sound
         JSR C32DA6      ; Target's address
         TYX             ; Move it to X
         LDA $14,X       ; Status LB
         STA $F8         ; Set as target's
         LDA $15,X       ; Status HB
         STA $FB         ; Set as target's
         JSR C32BD4      ; Adjust HP, status
         BRA C32C79      ; Redo GFX, test MP

; Fork: Invalid target
C32BCD:  JMP C3C5C6      ; Buzzer + Mosaic

; Adjust spell target's HP and status
C32BD4:  LDX $0B,Y       ; Max HP
         STX $11B2       ; Set target's
         PHY             ; Save index
         JSR C32DAE      ; Spell number
         LDX $00         ; Mode: Magic
         JSL $C20009     ; Get gain/status
         PLY             ; Actor's address
         LDA $9C         ; One target?
         REP #$21        ; 16-bit A; C-
         BEQ C32BF7      ; Branch if so
         LSR $11B0       ; Halve HP gain
C32BF7:  LDA $11B0       ; HP gain
         ADC $0009,Y     ; Add actor HP
         STA $0009,Y     ; Set actor HP
         JSR C32C35      ; Enforce max
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         LDA $9C         ; One target?
         BNE C32C55      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor's address
         JSL $C20006     ; Get gear data
         JSR C32DA6      ; Actor's address
         STY $67         ; Memorize it
         LDA $11D2       ; Immunities
         JSR C39995      ; Deny ailments
         LDA $11D4       ; Auto status
         JMP C399A4      ; Handle Float

; Keep HP from exceeding max HP, clear Carry if lower
C32C35:  LDX $0B,Y       ; Max HP
         JSR C30DD0      ; Add gear bonus
         JSR C30DFD      ; Cap at 9999
         LDX $09,Y       ; Current HP
         CPX $F3         ; Under max?
         BCC C32C55      ; Exit if so
         LDX $F3         ; Max HP
         STX $09,Y       ; Set HP
;        SEC             ; ...
C32C55:  RTS

; Keep MP from exceeding max MP, clear Carry if lower
C32C57:  LDX $0F,Y       ; Max MP
         JSR C30DD0      ; Add gear bonus
         JSR C30E0A      ; Cap at 999
         LDX $0D,Y       ; Current MP
         CPX $F3         ; Under max?
         BCC C32C76      ; Exit if so
         LDX $F3         ; Max MP
         STX $0D,Y       ; Set MP
;        SEC             ; ...
C32C76:  RTS

; Redraw party after spell usage, exit menu if short on MP
C32C79:  JSR C32C9C      ; Redraw party
         JSR C32D7A      ; Check caster gear
         JSR C32D9E      ; Caster's address
         JSR C32DAE      ; Spell used
         JSR C357DC      ; Define cost
         STX $E7         ; Memorize it
         LDX $0D,Y       ; Caster's MP
         CPX $E7         ; Can recast?
         BCS C32C9B      ; Exit if so
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$3C        ; C3/2DB7
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
C32C9B:  RTS

; Redraw party after spell or item usage
C32C9C:  LDA $4B         ; Cursor slot, 0 if MT
         STA $9C         ; Set portrait slot
         JSR C32561      ; Clear icons/portraits
         JSR C371A9      ; Clear names, stats
         JSR C3322E      ; Redo stats/icons/faces
         JSR C3739D      ; Load portrait colors
         JMP C37653      ; Queue portrait upload

; Establish whether spell target is valid
C32CAF:  LDA $0014,Y     ; Wound status?
         BMI C32CDB      ; Branch if so
         JSR C32DAE      ; Spell
         CMP #$2D        ; Cure?
         BEQ C32D11      ; Branch if so
         CMP #$2E        ; Cure 2?
         BEQ C32D11      ; Branch if so
         CMP #$2F        ; Cure 3?
         BEQ C32D11      ; Branch if so
         CMP #$32        ; Antdot?
         BEQ C32D08      ; Branch if so
         CMP #$33        ; Remedy?
         BEQ C32CFF      ; Branch if so
         CMP #$22        ; Float?
         BEQ C32CE8      ; Branch if so
         CMP #$23        ; Imp?
         BEQ C32D1F      ; Succeed if so
         CMP #$2C        ; Dispel?
         BEQ C32CF1      ; Branch if so
         BRA C32D1D      ; Make spell fail

; Fork: Wound
C32CDB:  JSR C32DAE      ; Spell
         CMP #$30        ; Life?
         BEQ C32D1F      ; Succeed if so
         CMP #$31        ; Life 2?
         BEQ C32D1F      ; Succeed if so
         BRA C32D1D      ; Make spell fail

; Fork: Float
C32CE8:  LDA $0015,Y     ; Float status?
         BMI C32D1D      ; Fail if so
         BRA C32D1F      ; Make spell work

; Fork: Dispel
C32CF1:  LDA $0014,Y     ; Status LB
         AND #$7F        ; Ignore Wound...
         ORA $0015,Y     ; Add high byte
         AND #$90        ; Clear or Float?
         BEQ C32D1D      ; Fail if neither
         BRA C32D1F      ; Make spell work

; Fork: Remedy
C32CFF:  LDA $0014,Y     ; Dark? Poison?
         AND #$45        ; Or Petrify?
         BEQ C32D1D      ; Fail if none
         BRA C32D1F      ; Make spell work

; Fork: Antdot
C32D08:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C32D1D      ; Fail if not
C32D1F:  SEC             ; Make spell work
         RTS

; Fork: Cure spells
C32D11:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C32D1D      ; Fail if any
         JSR C32C35      ; At full HP?
         BCC C32D1F      ; Succeed if not
C32D1D:  CLC             ; Make spell fail
         RTS

; Handle spell usage on party
C32D21:  STZ $AF         ; Valid target: N
         LDA #$01        ; Half gain, etc.
         STA $9C         ; Set heal mode
         JSR C32D67      ; Get LV, Mag.Pwr
         TDC             ; Member: 1st
C32D2B:  PHA             ; Save member
         JSR C32DA_      ; Actor's address
         BEQ C32D53      ; Skip if nobody
         JSR C32CAF      ; Valid target?
         BCC C32D53      ; Skip if not
         LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         JSR C32BD4      ; Adjust HP, status
         JSR C32D67      ; Get LV, Mag.Pwr
         LDA $AF         ; 1st valid target?
         BNE C32D53      ; Branch if not
         JSR C30F50      ; Play heal sound
         JSR C32D85      ; Lower caster's MP
         INC $AF         ; Valid target: Y
C32D53:  TDC             ; Clear A
         PLA             ; Member slot
         INC A           ; Member slot +1
         CMP #$04        ; Done all 4?
         BNE C32D2B      ; Loop if not
         LDA $AF         ; Is any valid?
         BNE C32D64      ; Branch if so
         JSR C3C5C6      ; Buzzer + Mosaic
C32D64:  JMP C32C79      ; Redo GFX, test MP

; Load caster's Mag.Pwr and level (for C2/0009)
C32D67:  JSR C32D7A      ; Define stats
         LDA $11A0       ; Mag.Pwr
         STA $11AE       ; Memorize it
         JSR C32D9E      ; Actor's address
         LDA $0008,Y     ; Level
         STA $11AF       ; Memorize it
         RTS

; Load member's stats and properties with gear
C32D7A:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Decrease caster's MP
C32D85:  JSR C32DAE      ; Spell
         JSR C357DC      ; Define cost
         STX $E7         ; Memorize it
         JSR C32D9E      ; Define Y
         REP #$20        ; 16-bit A
         LDA $000D,Y     ; Actor's MP
         SEC             ; Prepare SBC
         SBC $E7         ; Subtract cost
         STA $000D,Y     ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Get member's SRAM block address
C32D9E:  TDC             ; Clear A
         LDA $28         ; Member slot
         BRA C32DA_      ; Branch below

; Get target's SRAM block address
C32DA6:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
C32DA_:  ASL A           ; Double it
         TAX             ; Index it
         LDY $6D,X       ; SRAM address
         RTS

; Get selected spell
C32DAE:  TDC             ; Clear A
         LDA $99         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell
         RTS

; 3C: Return to Magic menu
C32DB7:  JSR C335F7      ; Reset/Stop stuff
         JSR C3719C      ; Set Win1 bounds
         LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         JSR C35482      ; Set to shift text
         JSR C3533D      ; Draw menu, etc.
         JSR C30833      ; Queue cursor OAM
         JSR C32190      ; Create scrollbar
         JSR C35245      ; Load navig data
         JSR oldcur      ; Restore cursor pos
         JSR C3524E      ; Relocate cursor
         JSR C321B8      ; Draw spells, etc.
         JSR C30ED9      ; Upload BG3 A+B
         JSR C313D3      ; Refresh screen
         LDY $00         ; X: 0
         STY $35         ; Set BG1 X-Pos
         JSR C31BFF      ; Queue desc anim
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30F68      ; Queue lists upload
         LDA #$1A        ; C3/2855
         STA $27         ; Queue Magic menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 3D: Handle multitarget spell
C32E13:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C32E2B      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$03        ; Using left/right?
         BEQ C32E36      ; Branch if not
C32E2B:  JSR C32E52      ; Swap cursors
         LDA #$3B        ; C3/2B49
         STA $26         ; Next: One target
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle A
C32E36:  LDA $08         ; Pushing A?
         BPL C32E3F      ; Branch if not
         JMP C32D21      ; Handle spell

; Fork: Handle B
C32E3F:  LDA $09         ; Pushing B?
         BPL C32E6B      ; Exit if not
         JSR C32E52      ; Swap cursors
         LDA #$3C        ; C3/2DB7
         STA $27         ; Queue Magic menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Revert to a single target for spell
C32E52:  JSR C33033      ; Preload nav data
         JSR C30833      ; Queue cursor OAM
         LDY #C3305B     ; C3/305B
         JSR qanim0      ; Queue D-Pad fn
         JSR C3121B      ; Run anim queue
         LDA $5F         ; Old cursor row
         STA $4E         ; Set as current
         LDA #$08        ; Blinkers: Off
         TRB $46         ; Set menu flag
C32E6B:  RTS

; Swap actor info for switched members
C32E6C:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         TAX             ; Index it
         LDA $4B         ; Chosen slot B
         TAY             ; Index it
         LDA $75,X       ; A's party info
         PHA             ; Memorize it
         LDA $0075,Y     ; B's party info
         STA $75,X       ; Set as A's
         PLA             ; A's party info
         STA $0075,Y     ; Set as B's
         LDA $69,X       ; A's actor ID
         PHA             ; Memorize it
         LDA $0069,Y     ; B's actor ID
         STA $69,X       ; Set as A's
         PLA             ; A's actor ID
         STA $0069,Y     ; Set as B's
         TDC             ; Clear A
         TXA             ; Chosen slot A
         ASL A           ; Double it
         TAX             ; Index it
         TYA             ; Chosen slot B
         ASL A           ; Double it
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA $6D,X       ; A's data adr
         PHA             ; Memorize it
         LDA $006D,Y     ; B's data adr
         STA $6D,X       ; Set as A's
         PLX             ; A's data adr
         STX $6D,Y       ; Set as B's
         SEP #$20        ; 8-bit A
         RTS

; Toggle member's row, set to shift portrait
C32EAB:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $75,X       ; Party info
         STA $E0         ; Memorize it
         LDA $60,X       ; Queue index
         TAX             ; Index it
         LDA #$20        ; Row bit
         BIT $E0         ; Front row?
         BEQ C32EC4      ; Branch if so
         TRB $E0         ; Row: Front
         LDA #$03        ; Shift: Right
         BRA C32ECA      ; Skip 2 lines
C32EC4:  TSB $E0         ; Row: Back
         LDA #$02        ; Shift: Left
C32ECA:  STA $7E3649,X   ; Set anim mode
;        TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $E0         ; Party info
         STA $75,X       ; Set member's
         RTS

; Set to delete all portraits
C32ED7:  TDC             ; Clear A
         LDX #$0003      ; 1st: Member 4
.loop    PHX             ; Save member
         LDA $60,X       ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Portrait: Off
         PLX             ; Member slot
         DEX             ; Member slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Jump table for main menu
C32F07:  dw C32F21       ; Item
         dw C32F2B       ; Skills
         dw C32F2B       ; Equip
         dw C32F2B       ; Relic
         dw C32F2B       ; Status
         dw C32F15       ; Config
         dw C32F45       ; Save

; Invoke Config menu
C32F15:  STZ $5F         ; Cursor: Bat.Mode
         STZ $26         ; Next: Fade-out
         LDA #$0D        ; C3/1CE3
         STA $27         ; Queue Config
         JMP C30F1D      ; Sound: Click

; Invoke Item menu
C32F21:  STZ $26         ; Next: Fade-out
         LDA #$07        ; C3/1B3C
         STA $27         ; Queue Item menu
         JMP C30F1D      ; Sound: Click

; Initialize portrait targeting with main menu command
C32F2B:  LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C33033      ; Preload nav data
         LDY #C3305B     ; C3/305B
         JSR qanim0      ; Queue D-Pad fn
         JSR C32FA1      ; Create blinker
         LDA #$06        ; C3/1E4E
         STA $26         ; Next: Targeting
         JMP C30F1D      ; Sound: Click

; Invoke Save menu if allowed
C32F45:  LDA $0201       ; Can save here?
         BPL C32F5A      ; Fail if not
         STZ $26         ; Next: Fade-out
         LDA #$13        ; C3/1D06
         STA $27         ; Queue Save menu
         JMP C30F1D      ; Sound: Click
C32F5A:  JMP C3C5C6      ; Buzzer + Mosaic

; Initiate shifting to Order menu
C32F61:  LDA #$02        ; List cursor: Off
         TRB $46         ; Set menu flag
         JSR C33033      ; Preload nav data
         LDY #C3305B     ; C3/305B
         JSR qanim0      ; Queue D-Pad fn
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$05        ; Blinker: Off
         TRB $46         ; Order cursor: Off
         LDA #$0F        ; C3/247F
         STA $27         ; Queue: Choice 1
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Pan screen
         RTS

; Create blinking cursor for Espers menu
C32F86:  LDY #C30956     ; C3/0956
         JSR qanim2      ; Queue OAM fn
         PEA $3638       ; Pos: 56, 54
         JMP C3F90Y      ; Set sprite's

; Create blinking cursor to the right of main cursor
C32FA1:  LDY #C30882     ; C3/0882
         JSR qanim2      ; Queue OAM fn
         LDA $55         ; Cursor's X
         INC A           ; +1 px right
         INC A           ; +1 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $56         ; Cursor's Y
         BRA C32FB_      ; Set blinker Y

; Create blinking cursor to northeast of main cursor
C32FBC:  LDY #C30882     ; C3/0882
         JSR qanim1      ; Queue OAM fn
         LDA $55         ; Cursor's X
         CLC             ; Prepare ADC
         ADC #$04        ; +4 px right
         STA $7E33CA,X   ; Set blinker X
         LDA $56         ; Cursor's Y
         SEC             ; Prepare SBC
         SBC #$04        ; +4 px up
C32FB_:  STA $7E344A,X   ; Set blinker Y
         RTS

; Update cursor position in main menu list
C32FDD:  BNE C33006      ; If mode 1

; Mode 0: Initialize data
C32FE5:  LDA #$02        ; Show cursor: Y
         TSB $46         ; Set menu flag
         INC $3649,X     ; Mode +1
         LDY #C33020     ; C3/3020
         JSR C30681      ; Load navig data
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C33000      ; Branch if not
         LDY $022B       ; Former position
         STY $4D         ; Set as current
C33000:  LDY #C33025     ; C3/3025
         JSR C306C3      ; Set cursor X/Y

; Mode 1: Update position
C33006:  LDA $46         ; Menu flags
         BIT #$02        ; Delete cursor?
         BEQ C3301E      ; Dequeue if so
         JSR C307B0      ; Handle D-Pad
         LDY #C33025     ; C3/3025
         JSR C306C3      ; Set cursor X/Y
         LDY $4D         ; Cursor position
         STY $022B       ; To cursor memory
         SEC             ; Set to requeue
         RTS             ; Exit
C3301E:  CLC             ; Set to dequeue
         RTS

; Preload nav data for portrait selection, disable empty slots
C33033:  JSR C3304C      ; Load navig data
         TDC             ; Clear A
         TAX             ; 1st: Member 1
C33039:  LDA $69,X       ; Actor in slot
         BPL C33045      ; Skip if any
         PHX             ; Save slot
         TXA             ; Move it to A
         ASL A           ; Double it
         TAX             ; Reindex it
         STZ $85,X       ; Disable slot
         PLX             ; Member slot
C33045:  INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C33039      ; Loop if not
         RTS

; Preload navigation data for portrait selection
C3304C:  LDX #$000C      ; Base index
C3304E:  LDA.L C330DD,X  ; Navig data
         STA $80,X       ; Save in RAM
         DEX             ; Index -1
         BPL C3304E      ; Loop till < 0
         RTS

; Update movable cursor's position for portrait selection
C3305B:  BNE C330AF      ; If mode 1

; Mode 0: Initialize data
C33063:  LDA #$14        ; Main cursor: On
         TSB $46         ; Enable D-Pad
         INC $3649,X     ; Mode +1
         JSR C33090      ; Load navig data
         LDA $45         ; Menu flags
         ASL A           ; Skip cursor mem?
         BMI C33081      ; Branch if so
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BPL C33081      ; Branch if not
         LDY $022D       ; Former position
         STY $4D         ; Set as current
C33081:  JSR C330A3      ; Relocate cursor
         LDA $55         ; On empty slot?
         BNE C3308E      ; Exit if not
         JSR C33090      ; Target leader
         JSR C330A3      ; Relocate cursor
C3308E:  SEC             ; Set to requeue
         RTS

; Load custom nav data for portrait selection, target leader
C33090:  LDY #$0080      ; 00/0080
         TDC             ; Src HB: 00
         JSR C30683      ; Load navig data
         JMP C306A1      ; Target leader

; Set portrait cursor's slot and base pixel position
C330A3:  LDY #$0085      ; 00/0085
         STY $E7         ; Set src LBs
         STZ $E9         ; Src HB: 00
         JMP C306C6      ; Relocate cursor

; Mode 1: Update position
C330AF:  LDA $45         ; Menu flags
         ASL A           ; Skip cursor mem?
         BMI C330BA      ; Branch if so
         LDY $4D         ; Cursor position
         STY $022D       ; To cursor memory
C330BA:  LDA $46         ; Menu flags
         BIT #$04        ; Delete cursor?
         BEQ C330DB      ; Dequeue if so
         BIT #$10        ; Swapping chars?
         BEQ C330D9      ; Exit if so
C330C6:  JSR C307B0      ; Handle D-Pad
         JSR C330A3      ; Relocate cursor
         LDA $55         ; On empty slot?
         BEQ C330C6      ; Retarget if so
C330D9:  SEC             ; Set to requeue
         RTS             ; Exit
C330DB:  CLC             ; Set to dequeue
         RTS

; Queue menu fade-out
C330EA:  LDY #C3313A     ; C3/313A
         JMP qanim0      ; Put in queue

; Queue menu fade-in
C330F1:  LDY #C33165     ; C3/3165
         JMP qanim0      ; Put in queue

; Queue mosaic effect
C330F8:  LDY #C330FF     ; C3/30FF
         JMP qanim0      ; Put in queue

; Process queued mosaic effect
C330FF:  BNE C33114      ; If mode 1

; Mode 0: Initialize mosaic
C33107:  INC $3649,X     ; Mode +1
         STZ $33CA,X     ; 1st: C3/3132
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set timer

; Mode 1: Sustain mosaic
C33114:  LDA $3349,X     ; Timer expired?
         BEQ C33130      ; Dequeue if so
         DEC $3349,X     ; Timer -1
;        TDC             ; Clear A
         LDA $33CA,X     ; Table index
         INC $33CA,X     ; Table index +1
         TAX             ; Index original
         LDA.L C33132,X  ; Parameters
         STA $B5         ; Save in RAM
         SEC             ; Set to requeue
         RTS             ; Exit
C33130:  CLC             ; Set to dequeue
         RTS

; Mosaic parameters
C33132:  db $17          ; Intensity 1 for BG1-BG3
         db $27          ; Intensity 2 for BG1-BG3
         db $37          ; Intensity 3 for BG1-BG3
         db $47          ; Intensity 4 for BG1-BG3
         db $37          ; Intensity 3 for BG1-BG3
         db $27          ; Intensity 2 for BG1-BG3
         db $17          ; Intensity 1 for BG1-BG3
         db $07          ; Intensity 0 for BG1-BG3

; Process queued menu fade-out
C3313A:  BNE C3314C      ; If mode 1

; Mode 0: Initialize brightness
C33142:  INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C3314C:  LDY $20         ; Timer expired?
         BEQ C3315F      ; Finalize if so
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC A           ; Next BRT -1
         DEC A           ; Next BRT -1
         STA $33CA,X     ; Save changes
         SEC             ; Set to requeue
         RTS             ; Exit
C3315F:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued menu fade-in
C33165:  BNE C33177      ; If mode 1

; Mode 0: Initialize brightness
C3316D:  INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT

; Mode 1: Increase brightness
C33177:  LDY $20         ; Timer expired?
         BEQ C3318A      ; Finalize if so
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC A           ; Next BRT +1
         INC A           ; Next BRT +1
         STA $344A,X     ; Save changes
         SEC             ; Set to requeue
         RTS             ; Exit
C3318A:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Draw and upload main menu
C33190:  JSR C340B9      ; Apply user font
         JSR bg2b_cl     ; Clear BG2 A+B
         JSR C371AD      ; Clear BG1 map B
         JSR C371D5      ; Clear BG3 map B
         LDX #C33256     ; C3/3256
         JSR boxes       ; Draw most boxes
         JSR C3320B      ; Draw stats, etc.
         JSR C33307      ; Draw time
         JSR C3328E      ; Draw menu list
         JMP up_txt      ; Upload text maps

; Draw and upload save confirmation menu
C331C3:  PEA C3382D      ; Text ptrs loc
         LDA #$05        ; Strings: 5
         BRA C331E_      ; Skip 2 lines

; Draw and upload load confirmation menu
C331E7:  PEA C33825      ; Text ptrs loc
         LDA #$04        ; Strings: 4
C331E_:  PHA             ; Memorize it
         JSR C340B9      ; Apply user font
         JSR C37616      ; Load portraits
         JSR C3739D      ; And their colors
         JSR C33243      ; Upload skin
         LDX #C33262     ; C3/3262
         JSR C303C4      ; Draw main window
         LDX #C33266     ; C3/3266
         JSR C303C4      ; Draw Yes/No box
         JSR C3320B      ; Draw stats, etc.
         JSR C33330      ; Draw time
         JSR C3D24D      ; Color: User's
         PLA             ; String count
         PLX             ; Text ptrs loc
         JSR C3714E      ; Draw question
         JMP up_txt      ; Upload text maps

; Draw elements shared by main menu and save file submenus
C3320B:  TDC             ; Gradient set: 0
         JSL $D4CA1D     ; Create gradient
         LDX #C3325A     ; C3/325A
         JSR boxes_      ; Draw small boxes
         JSR C33225      ; Draw party info
         BRA C332BC      ; Draw game stats

; Draw party info
C33225:  JSR C371A9      ; Clear BG1 map A
         JSR C371D0      ; Clear BG3 map A
         JSR C371DA      ; Clear BG3 map C
C3322E:  JSR C3338C      ; Handle member 1
         JSR C333D8      ; Handle member 2
         JSR C33424      ; Handle member 3
         JMP C33470      ; Handle member 4

; Upload skin for viewed save file
C33243:  TDC             ; Clear A
         LDA $66         ; File viewed
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3324_-2,X); Upload skin

; Jump table for the above
C3324_:  dw C33B75       ; Handle file 1
         dw C33B91       ; Handle file 2
         dw C33BAD       ; Handle file 3

; Draw list of submenus in main menu
C3328E:  JSR C3D24D      ; Color: User's
         LDX #C337F1     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C3712C      ; Do Item..Status
         LDX #C33821     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3714E      ; Do Equip/Config
         LDA $0201       ; Can save here?
         BPL C332B1      ; Branch if not
         LDA #$20        ; Color: User's
         BRA C332B3      ; Skip a line
C332B1:  LDA #$24        ; Color: Gray
C332B3:  STA $29         ; Set palette
         LDY #C338BF     ; Text pointer
         JMP C30326      ; Draw "Save"

; Draw most text in small windows of main menu or save file submenu
C332BC:  JSR C3D24D      ; Color: User's
         LDY #C338CC     ; Text pointer
         JSR C302F9      ; Draw ":"
         JSR C3D252      ; Color: Blue
         LDX #C337EB     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw SE titles
         LDY #C338D6     ; Text pointer
         JSR C30326      ; Draw "Gp"
         JSR C33369      ; Cap GP
         JSR C3D24D      ; Color: User's
         LDY $1866       ; Steps LBs
         STY $F1         ; Memorize them
         LDA $1868       ; Steps HB
         STA $F3         ; Memorize it
         JSR C30605      ; Turn into text
         LDX #$7DF7      ; Text position
         JSR C3052F      ; Draw step count
         PEA $7EB7       ; Text position
gp_pty:  LDY $1860       ; Gold LBs
         STY $F1         ; Memorize them
         LDA $1862       ; Gold HB
         STA $F3         ; Memorize it
         JSR C30605      ; Turn into text
         PLX             ; Text position
         JMP C3052F      ; Draw GP total

; Draw time in main menu
C33307:  LDA $1188       ; Timer 0 flags
         BIT #$10        ; Override clock?
         BEQ C33324      ; Branch if not
         LDY $1189       ; Countdown timer
         JSR C3334D      ; Divide by 60
         JSR C3334D      ; Divide by 60
         LDA $E7         ; Minutes
         STA $1863       ; Set shown hours
         LDA $4216       ; Seconds
         STA $1864       ; Set shown mins
         BRA C33330      ; Draw time

; Fork: Normal clock
C33324:  LDY $021B       ; Hours, mins
         STY $1863       ; Save in SRAM
         LDA $021D       ; Seconds
         STA $1865       ; Save in SRAM

; Fork: Draw time
C33330:  JSR C3D24D      ; Color: User's
         LDA $1863       ; Shown hours
         JSR C30563      ; Turn into text
         LDX #$7CFB      ; Text position
         JSR C30539      ; Draw 2 digits
         LDA $1864       ; Shown minutes
         JSR C3057C      ; Turn into text
         LDX #$7D01      ; Text position
         JMP C30539      ; Draw 2 digits

; Divide countdown timer's value by 60
C3334D:  STY $4204       ; Set dividend
         LDA #$3C        ; 60
         STA $4206       ; Set divisor
         JSR x16         ; Waste 20 cycles
         LDY $4214       ; Quotient
         STY $E7         ; Memorize it
         RTS

; Enforce GP cap
C33369:  LDY #$967F      ; Cap LBs
         CPY $1860       ; C- if < GP LBs
         LDA #$98        ; Cap HB
         SBC $1862       ; Deduct GP w/ C
         BCS C33385      ; Exit if < 10M
         STY $1860       ; Set gold LBs
         LDA #$98        ; Cap HB
         STA $1862       ; Set gold HB
C33385:  RTS

; Hi-fork: Hide portrait
C33386:  JSR C30A8D      ; Init portrait
         JMP C334B6      ; Hide portrait

; Draw info for member 1
C3338C:  LDA $69         ; Nobody here?
         BMI C33386      ; Abort if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         JSR C3658A      ; Color: Blue
         LDX #C33809     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         LDY #$38E7      ; Class/KO pos
         LDX #$1578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C334C2      ; Do class/status
         LDX #C337F9     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3712C      ; Draw both "/"
         LDY #$38D9      ; Text position
         JSR C3356A      ; Draw actor name
         LDX #C333C8     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
         JMP C30A8D      ; Create portrait

; Hi-fork: Hide portrait
C333D2:  JSR C30AB6      ; Init portrait
         JMP C334B6      ; Hide portrait

; Draw info for member 2
C333D8:  LDA $6A         ; Nobody here?
         BMI C333D2      ; Abort if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         JSR C3658A      ; Color: Blue
         LDX #C3380F     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         LDY #$3A67      ; Class/KO pos
         LDX #$4578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C334C2      ; Do class/status
         LDX #C337FD     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3712C      ; Draw both "/"
         LDY #$3A59      ; Text position
         JSR C3356A      ; Draw actor name
         LDX #C33414     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
         JMP C30AB6      ; Create portrait

; Hi-fork: Hide portrait
C3341E:  JSR C30AE1      ; Init portrait
         BRA C334B6      ; Hide portrait

; Draw info for member 3
C33424:  LDA $6B         ; Nobody here?
         BMI C3341E      ; Abort if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         JSR C3658A      ; Color: Blue
         LDX #C33815     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         LDY #$3BE7      ; Class/KO pos
         LDX #$7578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C334C2      ; Do class/status
         LDX #C33801     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3712C      ; Draw both "/"
         LDY #$3BD9      ; Text position
         JSR C3356A      ; Draw actor name
         LDX #C33460     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
         JMP C30AE1      ; Create portrait

; Draw info for member 4
C33470:  LDA $6C         ; Nobody here?
         BMI C3346A      ; Abort if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         JSR C3658A      ; Color: Blue
         LDX #C3381B     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         LDY #$3D67      ; Class/KO pos
         LDX #$A578      ; Icon position
         STZ $48         ; Anim mode: 0
         JSR C334C2      ; Do class/status
         LDX #C33805     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3712C      ; Draw both "/"
         LDY #$3D59      ; Text position
         JSR C3356A      ; Draw actor name
         LDX #C334AC     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
         JMP C30B0C      ; Create portrait

; Fork: Hide portrait
C3346A:  JSR C30B0C      ; Init portrait
;        BRA C334B6      ; Hide portrait

; Hide portrait for vacant member slot
C334B6:  LDA #$D8        ; Base Y: 216
         STA $7E344A,X   ; Set sprite's
         RTS

; Display actor's status or class (excludes Status menu)
C334C2:  STX $E7         ; Save icon pos
         JSR C335E1      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C3354B      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status LB
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in bits 1-3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status HB
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         BEQ C33544      ; Use class if none
icons:   STZ $F1         ; Sprite index LB
         STZ $F2         ; Sprite index HB
         LDX #$0007      ; Status left: 7
C334EC:  PHX             ; Save counter
         ASL A           ; Got current?
         BCC C33537      ; Skip if not
         PHA             ; Save status
         LDY #C382C9     ; C3/82C9
         JSR qanim3      ; Queue icon OAM
         JSR C3F9A6      ; Follow BG1: Y
         LDA $48         ; Anim mode
         STA $7E3649,X   ; Set icon's
         PHX             ; Save queue index
         LDX $F1         ; Sprite index
         REP #$20        ; 16-bit A
         LDA $D8ECAF,X   ; Anim table ptr
         TAY             ; Put in Y
         PLX             ; Queue index
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Anim ptr HB
         JSR anm_st      ; Set icon's ptr
         LDY $E7         ; Position
         JSR objpos      ; Set icon's
         LDA #$0A        ; Modifier: 10
         CLC             ; Prepare ADC
         ADC $E7         ; Add current X
         STA $E7         ; Set current X
         PLA             ; Statuses
C33537:  INC $F1         ; Sprite index +1
         INC $F1         ; Sprite index +1
         PLX             ; Statuses left
         DEX             ; One less left
         BNE C334EC      ; Loop till last
         JMP C3D24D      ; Color: User's
                         ; ^ For stats

; Fork: Draw actor class
C33544:  JSR C3D24D      ; Color: User's
         BRA C33583      ; Draw class

; Fork: Draw "Wounded"
C3354B:  LDX $00         ; Index: 0
C33553:  LDA.L C337E3,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C33553      ; Loop if not
         JSR C3880B      ; Color: Gray
         JMP C387B_      ; Draw string

; Draw actor name
C3356A:  JSR C335E1      ; Set pos/WRAM/Y
C3356D:  LDX #$0006      ; Letters: 6
C33570:  LDA $0002,Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE C33570      ; Loop till last
         JMP C387B_      ; Draw string

; Draw actor class
C33580:  JSR C335E1      ; Set pos/WRAM/Y
C33583:  LDA $0000,Y     ; Actor
         XBA             ; Put it in B
         LDX.W #!act_cs  ; Letters: 7
         LDA.B #!act_cp!h; Text ptr HB
         LDY.W #!act_cp  ; Text ptr LBs
         JSR fw_txt      ; Load name
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JMP C387B_      ; Draw string

; Draw equipped esper
C335AE:  JSR C335E1      ; Set pos/WRAM/Y
         LDA $001E,Y     ; Actor's esper
         CMP #$FF        ; None?
         BEQ C335D0      ; Blank if so
drw_esp: XBA             ; Put it in B
         LDX.W #!esp_ns  ; Letters: 8
         LDA.B #!esp_np!h; Text ptr HB
         LDY.W #!esp_np  ; Text ptr LBs
         JSR fw_txt      ; Load name
         JMP C387B_      ; Draw string

; Fork: Blank esper name
C335D0:  LDY.W #!esp_ns  ; Spaces: 8
         JMP spacedr     ; Draw 8 spaces

; Prepare name drawing
C335E1:  JSR wm9E8B      ; WRAM: 7E/9E8B
         REP #$20        ; 16-bit A
         TYA             ; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDY $67         ; Actor address
         RTS

; Reset OAM and anim queue; disable screen, interrupts, pad, HDMA
C335F7:  JSR C3117F      ; Reset OAM, queue
         JMP C3D4E5      ; Disable pad, etc.

; Prepare fade-in
C33609:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JMP C313D3      ; Refresh screen

; Redraw time in main menu
C33610:  JSR C30FA4      ; Queue BG3 upload
         JMP C33307      ; Draw time

; Queue main screen designation HDMA for main menu
C33616:  LDX #$00DE      ; Base index
         LDA #$17        ; BG1-3, sprites
C3361A:  STA $7E9A09,X   ; Set MS desig.
         DEX             ; Index -1
         BPL C3361A      ; Loop till < 0
         LDA #$40        ; 1Rx1B via ptrs
         STA $4360       ; Set DMA mode
         LDA #$2C        ; $212C
         STA $4361       ; To MS desig.
         LDY #C33643     ; C3/3643
         STY $4362       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4364       ; Set src HB
         LDA #$7E        ; Bank: 7E
         STA $4367       ; Set indir HB
         LDA #$40        ; Channel: 6
         TSB $43         ; Queue HDMA-6
         RTS

; Main screen designation table for main menu
C33643:  db $F0,$09,$9A  ; 112 lines, use $9A09
         db $F0,$79,$9A  ; 112 lines, use $9A79
         db $00          ; End

; Queue member swap animation for Order menu
C3364A:  LDA $28         ; First choice
         CMP $4B         ; Above second?
         BCC C33665      ; Branch if so
         LDY #C3369C     ; C3/369C
         JSR qanim3      ; Queue B's anim
         JSR C33689      ; Set slot B's Y
         LDY #C336E7     ; C3/36E7
         JSR qanim3      ; Queue A's anim
         BRA C3367A      ; Set slot A's Y

; Fork: First choice is above second
C33665:  LDY #C3369C     ; C3/369C
         JSR qanim3      ; Queue A's anim
         JSR C3367A      ; Set slot A's Y
         LDY #C336E7     ; C3/36E7
         JSR qanim3      ; Queue B's anim
         BRA C33689      ; Set slot B's Y

; Fork: Set base scanline for slot A
C3367A:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         BRA C3368_      ; Skip 2 lines

; Fork: Set base scanline for slot B
C33689:  TDC             ; Clear A
         LDA $4B         ; Chosen slot B
C3368_:  TXY             ; Queue index
         TAX             ; Index slot
         LDA.L C33698,X  ; Base scanline
         TYX             ; Queue index
         STA $7E33CA,X   ; Put in queue
         RTS

; Base scanlines for member swap animation
C33698:  db $0D          ; Member slot 1
         db $3D          ; Member slot 2
         db $6D          ; Member slot 3
         db $9D          ; Member slot 4

; Erase member slot contents from the top down, and vice versa
C3369C:  BNE C336CA      ; If mode 1

; Mode 0: Erase 4 lines
C336AB:  LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C336C2      ; Unmask if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C3373F      ; Hide 4 lines
         STA $33CA,X     ; Save scanline
         SEC             ; Set to requeue
         RTS

; Fork: Start unmasking
C336C2:  INC $3649,X     ; Mode +1
         DEC $33CA,X     ; Scanline -1

; Mode 1: Print 4 lines
C336CA:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C336E3      ; Exit if not
         LDA $22         ; Timer expired?
         BEQ C336E5      ; Dequeue if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C33755      ; Unhide 4 lines
         STA $33CA,X     ; Save scanline
C336E3:  SEC             ; Set to requeue
         RTS             ; Exit
C336E5:  CLC             ; Set to dequeue
         RTS

; Erase member slot contents from the bottom up, and vice versa
C336E7:  CMP #$02        ; Mode 1?
         BEQ C336FF      ; Branch if so
         BCS C33720      ; If mode 2

; Mode 0: Start from bottom
C336F1:  INC $3649,X     ; Mode +1
         LDA $33CA,X     ; Top scanline
         CLC             ; Prepare ADC
         ADC #$2F        ; Go 47 px down
         STA $33CA,X     ; Save changes

; Mode 1: Erase 4 lines
C336FF:  LDA $22         ; Time left
         CMP #$0C        ; 12 frames?
         BEQ C33718      ; Unmask if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$06        ; On MS: BG2+BG3
         JSR C33755      ; Hide 4 lines
         STA $33CA,X     ; Save scanline
         DEC $22         ; Anim timer -1
         SEC             ; Set to requeue
         RTS

; Fork: Start ummasking
C33718:  INC $3649,X     ; Mode +1
         INC $33CA,X     ; Scanline +1

; Mode 2: Print 4 lines
C33720:  LDA $45         ; Menu flags
         BIT #$08        ; Got go-signal?
         BEQ C3373B      ; Exit if not
         LDA $22         ; Timer expired?
         BEQ C3373D      ; Dequeue if so
;        TDC             ; Clear A
         LDA $33CA,X     ; Scanline
         TAY             ; Index it
         LDA #$17        ; On MS: BGs+OBJ
         JSR C3373F      ; Unhide 4 lines
         STA $33CA,X     ; Save scanline
         DEC $22         ; Anim timer -1
C3373B:  SEC             ; Set to requeue
         RTS             ; Exit
C3373D:  CLC             ; Set to dequeue
         RTS

; Enable or disable desired layers on next 4 lines below
C3373F:  STA $9A09,Y     ; MS desig L1
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L2
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L3
         INY             ; Scanline +1
         STA $9A09,Y     ; MS desig L4
         INY             ; Scanline +1
         TYA             ; Line number
         RTS

; Enable or disable desired layers on next 4 lines above
C33755:  STA $9A09,Y     ; MS desig L4
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L3
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L2
         DEY             ; Scanline -1
         STA $9A09,Y     ; MS desig L1
         DEY             ; Scanline -1
         TYA             ; Line number
         RTS

; Set to condense BG3 text in main menu
C3376B:  LDY #C3378A     ; C3/378A
         JMP bg3v_       ; Queue BG3 V-Pan

; 65: Shift screen left or right
C337AF:  LDA $20         ; Timer expired?
         BNE C337B7      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C337B7:  REP #$21        ; 16-bit A; C-
         LDA $35         ; BG1 X-Pos
         ADC $9C         ; Add scroll speed
         STA $35         ; Set BG1 X-Pos
         STA $39         ; Set BG2 X-Pos
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for non-shifted Status menu
C337C7:  LDY #C337D6     ; C3/37D6
         JMP C30681      ; Load navig data

; Handle D-Pad for non-shifted Status menu
C337CD:  JSR C307B0      ; Handle D-Pad
C337D0:  LDY #C337DB     ; C3/37DB
         JMP C306C3      ; Relocate cursor

; Load navigation data for Config page 1
C33927:  LDY #C33936     ; C3/3936
         JMP C30681      ; Load navig data

; Handle D-Pad for Config page 1
C3392D:  JSR C307B0      ; Handle D-Pad
C33930:  LDY #C3393B     ; C3/393B
         JMP C306C3      ; Relocate cursor

; Load navigation data for Config page 2
C3394F:  LDY #C3395E     ; C3/395E
         JMP C30681      ; Load navig data

; Handle D-Pad for Config page 2
C33955:  JSR C307B0      ; Handle D-Pad
C33958:  LDY #C33963     ; C3/3963
         JMP C306C3      ; Relocate cursor

; Draw Config menu, load navigation data, create arrow
C3396F:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDY #$FFFB      ; Y: -5
         STY $3F         ; Set BG3 Y-Pos
         JSR C371BC      ; Clear BG2 map A
         LDX #C33AB6     ; C3/3AB6
         JSR boxes_      ; Upload windows
         JSR C33A32      ; Load gauge colors
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR C3D252      ; Color: Blue
         LDY #C34E8F     ; Text pointer
         JSR C30326      ; Draw "Config"
         JSR C3658A      ; Color: Blue
         LDX #C34E81     ; Text ptrs loc
         LDA #$0A        ; Strings: 10
         JSR C3714E      ; Draw Bat.Mode, etc.
         LDX #C34DF5     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3712C      ; Draw Cursor, Contr.
         JSR C3D24D      ; Color: User's
         LDX #C34F00     ; Text ptrs loc
         LDA #$08        ; Strings: 8
         JSR C3712C      ; Draw Fast, etc.
         JSR C33C60      ; Draw Active, Wait
         JSR C33C8B      ; Draw Bat.Spd nums
         JSR C33CC6      ; Draw Msg.Spd nums
         JSR C33D07      ; Draw Window, Short
         JSR C33D30      ; Draw On and Off
         JSR C33D59      ; Draw Stereo, Mono
         JSR C33D84      ; Draw Reset, Memory
         JSR C33DAF      ; Draw Optimum, Empty
         JSR C33DDA      ; Draw Btn.Set options
         JSR C33E0B      ; Draw Single/Multiple
         JSR C3411D      ; Draw M.Order options
         JSR C341CB      ; Draw skin numbers
         JSR C34214      ; Draw skin palette
         JSR C342A4      ; Draw RGB info
         JSR C33AC9      ; Get nav data; BG1 Y
         JSR C30E93      ; Upload BG1 A+B
         JSR C30ED9      ; Upload BG3 A+B
         LDY #C33A54     ; C3/3A54
         JMP qanim1      ; Queue arrow OAM

; Draw empty color gauges
C33A24:  JSR txt30       ; Color: Gray
         LDX #C34EFA     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JMP C3712C      ; Draw text

; Load color gauge palette
C33A32:  LDA #$40        ; CGRAM: $0080
         STA $2121       ; To BG pal 4
         LDX $00         ; Color index: 0
C33A39:  REP #$20        ; 16-bit A
         LDA $D8E880,X   ; Font color
         STA $7E30C9,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0020      ; Done 16 colors?
         BNE C33A39      ; Loop if not
         RTS

; Update arrow in Config menu
C33A54:  BNE C33A7F      ; If mode 1

; Mode 0: Initialize arrow
C33A5C:  LDY #C33A9F     ; Anim table ptr
         JSR anm_c3      ; Set arrow's
         LDY #$1878      ; Pos: 120, 24
         JSR objpos      ; Set arrow's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C33A7F:  TXY             ; Queue index
         LDX $00         ; Arrow: Down
         LDA $4A         ; On first page?
         BEQ C33A89      ; Branch if so
         INX #2          ; Arrow: Up
C33A89:  REP #$20        ; 16-bit A
         LDA.L C33A9B,X  ; Anim table ptr
         STA $32C9,Y     ; Set arrow's
         JMP oamsec      ; Set OAM; requeue

; Switch to Config page 2
C33ABE:  LDY #$00FB      ; Y: 251
         STY $37         ; Set BG1 Y-Pos
         JSR C3394F      ; Load navig data
         JMP C33958      ; Relocate cursor

; Switch to Config page 1
C33AC9:  LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33927      ; Load navig data
         JMP C33930      ; Relocate cursor

; 50: Scroll to Config page 2
C33AD4:  LDA $20         ; Timer expired?
         BEQ C33AE9      ; Finalize if so
         LDA $4A         ; On page 2?...
         BNE C33AF0      ; Branch if so
         REP #$21        ; 16-bit A; C-
         LDA $37         ; BG1 Y-Pos
         ADC #$0010      ; Move 16 px down
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33AE9:  LDA #$01        ; Screen: 2nd
         STA $4A         ; Set active page
         JSR C33ABE      ; Switch screens
C33AF0:  BRA C33B1B      ; Next: Sustain menu

; 51: Scroll to Config page 1
C33AF5:  LDA $20         ; Timer expired?
         BEQ C33B0A      ; Finalize if so
         LDA $4A         ; On page 1?...
         BEQ C33B1B      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $37         ; BG1 Y-Pos
         SEC             ; Prepare SBC
         SBC #$0010      ; Move 16 px up
         STA $37         ; Save changes
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C33B0A:  STZ $4A         ; Page: 1st
         LDY #$FFFB      ; Y: -5
         STY $37         ; Set BG1 Y-Pos
         JSR C33927      ; Load navig data
         LDA #$09        ; Row: Controller
         STA $4E         ; Set cursor row
         JSR C33930      ; Relocate cursor
C33B1B:  LDA #$0E        ; C3/2325
         STA $26         ; Next: Sustain menu
         RTS

; Set Window 2 positions per scanline for Config menu
C33B20:  LDY #C33B4E     ; C3/3B4E
C33B2_:  STY $4352       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4354       ; Set src HB
         LDA #$01        ; 2Rx1B to PPU
         STA $4350       ; Set DMA mode
         LDA #$28        ; $2128, $2129
         STA $4351       ; To Win 2 L+R
         LDA #$20        ; Channel: 5
         TSB $43         ; Queue HDMA-5
         RTS

; Set Window 2 positions for main menu
C33B3F:  LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         LDX #$F708      ; Win2-L: 8
         STX $2128       ; Win2-R: 247
         RTS

; Window 2 positions per scanline for Config menu
C33B4E:  db $27,$FF,$FF  ; 39 lines: 255, 255
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $50,$08,$F7  ; 80 lines: 8, 247
         db $10,$FF,$FF  ; 16 lines: 255, 255
         db $00          ; End

; Upload skin graphics, load colors and tile attributes
C33B5B:  LDY #$7800      ; $7800
         STY $14         ; Set VRAM ptr
         LDA $1D4E       ; Skin, etc.
         JSR C33C04      ; Set source
         LDA $1D4E       ; Skin, etc.
         LDX #$0060      ; To 7E/312B
         JSR C33C2F      ; Load colors
         LDY #$1C00      ; Palette: 7
         JMP C303A9      ; Build skin map

; Upload skin for save file 1
C33B75:  LDY #$7A00      ; $7A00
         STY $14         ; Set VRAM ptr
         LDA $30674E     ; Skin, etc.
         LDY $91         ; Blank file?
         BNE C33B85      ; Branch if not
         TDC             ; Use skin 1
C33B85:  JSR C33C04      ; Set source
         JSR C314F3      ; Upload skin
         LDY #$1820      ; Tile+32, pal 6
         JMP C303A9      ; Build skin map

; Upload skin for save file 2
C33B91:  LDY #$7C00      ; $7C00
         STY $14         ; Set VRAM ptr
         LDA $30714E     ; Skin, etc.
         LDY $93         ; Blank file?
         BNE C33BA1      ; Branch if not
         TDC             ; Use skin 1
C33BA1:  JSR C33C04      ; Set source
         JSR C314F3      ; Upload skin
         LDY #$1440      ; Tile+64, pal 5
         JMP C303A9      ; Build skin map

; Upload skin for save file 3
C33BAD:  LDY #$7E00      ; $7E00
         STY $14         ; Set VRAM ptr
         LDA $307B4E     ; Skin, etc.
         LDY $95         ; Blank file?
         BNE C33BBD      ; Branch if not
         TDC             ; Use skin 1
C33BBD:  JSR C33C04      ; Set source
         JSR C314F3      ; Upload skin
         LDY #$1060      ; Tile+96, pal 4
         JMP C303A9      ; Build skin map

; Load skin colors for save file 1
C33BC9:  LDA $30674E     ; Skin, etc.
         LDY $91         ; Blank file?
         BNE C33BD4      ; Branch if not
         TDC             ; Use skin 1
C33BD4:  LDX #$0040      ; To 7E/310B
         JSR C33C2F      ; Load colors
         JMP C3153D      ; Refresh CGRAM

; Load skin colors for save file 2
C33BDD:  LDA $30714E     ; Skin, etc.
         LDY $93         ; Blank file?
         BNE C33BE8      ; Branch if not
         TDC             ; Use skin 1
C33BE8:  LDX #$0020      ; To 7E/30EB
         JSR C33C2F      ; Load colors
         JMP C3153D      ; Refresh CGRAM

; Load skin colors for save file 3
C33BF1:  LDA $307B4E     ; Skin, etc.
         LDY $95         ; Blank file?
         BNE C33BFC      ; Branch if not
         TDC             ; Use skin 1
C33BFC:  LDX $00         ; To 7E/30CB
         JSR C33C2F      ; Load colors
         JMP C3153D      ; Refresh CGRAM

; Set source for uploading skin graphics
C33C04:  AND #$0F        ; Skin number
         LDY #$0380      ; Skin data size
         JSR mul16       ; Skin x size
         STX $16         ; Set as src LBs
         LDA #$ED        ; Bank: ED
         STA $18         ; Set src HB
         LDY #$0400      ; Bytes: 1024
         STY $12         ; Set data size
         RTS

; Apply player's skin colors
C33C2F:  AND #$0F        ; Skin number
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         TAY             ; Index product
         LDA #$0E        ; Colors: 7
C33C52:  PHA             ; Save counter
         LDA $1D57,Y     ; Player color
         STA $7E30CB,X   ; Put in palette
         INY             ; Src index +1
         INX             ; Dst index +1
         PLA             ; Colors left
         DEC A           ; One less left
         BNE C33C52      ; Loop till last
         RTS

; Draw Bat.Mode settings
C33C60:  JSR C3880B      ; Color: Gray
         JSR C33C79      ; Draw "Active"
         JSR C33C82      ; Draw "Wait"
         JSR C3D24D      ; Color: User's
         LDA $1D4D       ; Game options
         AND #$08        ; Wait mode?
         BNE C33C82      ; Branch if so

; Fork: Draw "Active"
C33C79:  LDY #C34ECE     ; Text pointer
         JMP C30326      ; Draw "Active"

; Fork: Draw "Wait"
C33C82:  LDY #C34E07     ; Text pointer
         JMP C302F9      ; Draw "Wait"

; Draw Bat.Speed values
C33C8B:  JSR C3880B      ; Color: Gray
         LDY #C34E5C     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33CBA,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         JMP C341F7      ; Draw user speed

; Draw Msg.Speed values
C33CC6:  JSR C3880B      ; Color: Gray
         LDY #C34E6A     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C33CFB,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; Now 0-7
         JMP C341F7      ; Draw user speed

; Draw Cmd.Set settings
C33D07:  JSR C3880B      ; Color: Gray
         JSR C33D1E      ; Draw "Short"
         JSR C33D27      ; Draw "Window"
         JSR C3D24D      ; Color: User's
         LDA $1D4D       ; Window mode?
         BPL C33D27      ; Branch if so

; Fork: Draw "Short"
C33D1E:  LDY #C34E1A     ; Text pointer
         JMP C302F9      ; Draw "Short"

; Fork: Draw "Window"
C33D27: LDY #C34ED6      ; Text pointer
         JMP C30326      ; Draw "Window"

; Draw Gauge settings
C33D30:  JSR C3880B      ; Color: Gray
         JSR C33D47      ; Draw "On"
         JSR C33D50      ; Draw "Off"
         JSR C3D24D      ; Color: User's
         LDA $1D4E       ; Gauges off?
         BMI C33D50      ; Branch if so

; Fork: Draw "On"
C33D47:  LDY #C34E22     ; Text pointer
         JMP C302F9      ; Draw "On"

; Fork: Draw "Off"
C33D50:  LDY #C34E27     ; Text pointer
         JMP C302F9      ; Draw "Off"

; Draw Sound settings
C33D59:  JSR C3880B      ; Color: Gray
         JSR C33D72      ; Draw "Stereo"
         JSR C33D7B      ; Draw "Mono"
         JSR C3D24D      ; Color: User's
         LDA $1D4E       ; Game options
         AND #$20        ; Mono?
         BNE C33D7B      ; Branch if so

; Fork: Draw "Stereo"
C33D72:  LDY #C34E2C     ; Text pointer
         JMP C302F9      ; Draw "Stereo"

; Fork: Draw "Mono"
C33D7B:  LDY #C34E33     ; Text pointer
         JMP C302F9      ; Draw "Mono"

; Draw Cursor settings
C33D84:  JSR C3880B      ; Color: Gray
         JSR C33D9D      ; Draw "Reset"
         JSR C33DA6      ; Draw "Memory"
         JSR C3D24D      ; Color: User's
         LDA $1D4E       ; Game options
         ASL A           ; Cursor memory?
         BMI C33DA6      ; Branch if so

; Fork: Draw "Reset"
C33D9D:  LDY #C34EDE     ; Text pointer
         JMP C30326      ; Draw "Reset"

; Fork: Draw "Memory"
C33DA6:  LDY #C34E3A     ; Text pointer
         JMP C302F9      ; Draw "Memory"

; Draw Reequip settings
C33DAF:  JSR C3880B      ; Color: Gray
         JSR C33DC8      ; Draw "Optimum"
         JSR C33DD1      ; Draw "Empty"
         JSR C3D24D      ; Color: User's
         LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BNE C33DD1      ; Branch if not

; Fork: Draw "Optimum"
C33DC8:  LDY #C34E40     ; Text pointer
         JMP C302F9      ; Draw "Optimum"

; Fork: Draw "Empty"
C33DD1:  LDY #C34EE4     ; Text pointer
         JMP C30326      ; Draw "Empty"

; Draw Btn.Set settings
C33DDA:  JSR C3880B      ; Color: Gray
         JSR C33DF9      ; Draw "Normal"
         JSR C33E02      ; Draw "Custom"
         JSR C3D24D      ; Color: User's
         LDA $1D54       ; Game options
         ASL A           ; Default keys?
         BPL C33DED      ; Branch if so
         JSR C3ADEF      ; Apply user keys

; Fork: Draw "Custom"
C33E02:  LDY #C34E4F     ; Text pointer
         JMP C302F9      ; Draw "Custom"

; Fork: Normal mode
C33DED:  JSR C3ADFC      ; Reset buttons
C33DF9:  LDY #C34E48     ; Text pointer
         JMP C302F9      ; Draw "Normal"

; Draw Controller settings
C33E0B:  JSR C3880B      ; Color: Gray
         JSR C33E22      ; Draw "Single"
         JSR C33E2B      ; Draw "Multiple"
         JSR C3D24D      ; Color: User's
         LDA $1D54       ; Solo mode?
         BMI C33E2B      ; Branch if not

; Fork: Draw "Single"
C33E22:  LDY #C34EED     ; Text pointer
         JMP C30326      ; Draw "Single"

; Fork: Draw "Multiple"
C33E2B:  LDY #C34E56     ; Text pointer
         JMP C302F9      ; Draw "Multiple"

; Handle Config changes with D-Pad
C33E34:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Set C if right
         LDA $4A         ; On page 2?
         BNE .sound      ; Branch if so
         CPX #$000A      ; On "Sound"?
         BEQ .nosnd      ; Branch if so
.sound   JSR C30F0E      ; Sound: Cursor
.nosnd   LDA $0B         ; Semi-auto keys
         LSR A           ; Set C if right
         LDA $4A         ; On first page?
         BEQ C33E45      ; Branch if so
         JMP (C33E5C,X)  ; Handle page 2
C33E45:  JMP (C33E48,X)  ; Handle page 1

; Jump table for updating game options
C33E48:  dw C33E68       ; Bat.Mode
         dw C33E81       ; Bat.Speed
         dw C33EB2       ; Msg.Speed
         dw C33EEF       ; Cmd.Set
         dw C33F08       ; Gauge
         dw C33F21       ; Sound
         dw C33F55       ; Cursor
         dw C33F74       ; Reequip
         dw C33F8D       ; Button
         dw C33FA6       ; Controller
C33E5C:  dw C33FBF       ; Mag.Order
         dw C33FED       ; Window
         dw C34021       ; Viewed color
         dw C3405C       ; R
         dw C3407B       ; G
         dw C3409A       ; B

; Update Bat.Mode
C33E68:  LDA #$08        ; Bat.Mode bit
         TRB $1D4D       ; Mode: Active
         BCC .draw       ; If pushing left
         TSB $1D4D       ; Mode: Wait
.draw    JMP C33C60      ; Redraw text

; Update Bat.Speed
C33E81:  LDA $1D4D       ; Game options
         AND #$07        ; Get Bat.Speed
         TRB $1D4D       ; Clear in config
         BCC C33E9C      ; If pushing left

; Fork: Bat.Speed +1
C33E91:  CMP #$05        ; On "6"?
         BEQ C33EA5      ; Retain if so
         INC A           ; Speed +1
         BRA C33EA5      ; Apply changes

; Fork: Bat.Speed -1
C33E9C:  BEQ C33EA5      ; Retain if "1"
         DEC A           ; Speed -1

; Fork: Apply Bat.Speed
C33EA5:  TSB $1D4D       ; Update config
         JMP C33C8B      ; Redraw values

; Update Msg.Speed
C33EB2:  PHP             ; Save Carry
         LDA $1D4D       ; Game options
         AND #$70        ; Get Msg.Speed
         TRB $1D4D       ; Clear in config
         LSR A           ; Put in b3-b5
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-5
         PLP             ; Pushing right?
         BCC C33ED1      ; Branch if not

; Fork: Msg.Speed +1
C33EC6:  CMP #$05        ; On "6"?
         BEQ C33EDA      ; Retain if so
         INC A           ; Speed +1
         BRA C33EDA      ; Apply changes

; Fork: Msg.Speed -1
C33ED1:  DEC A           ; Speed -1
         BPL C33EDA      ; Retain if > 0
         INC A           ; Speed +1

; Fork: Apply Msg.Speed
C33EDA:  JSR x16         ; Speed x 16
         TSB $1D4D       ; Update config
         JMP C33CC6      ; Redraw values

; Update Cmd.Set mode
C33EEF:  LDA #$80        ; Cmd.Set bit
         TRB $1D4D       ; Mode: Window
         BCC .draw       ; If pushing left
         TSB $1D4D       ; Mode: Short
.draw    JMP C33D07      ; Redraw options

; Update gauge mode
C33F08:  LDA #$80        ; Gauge bit
         TRB $1D4E       ; Gauge: On
         BCC .draw       ; If pushing left
         TSB $1D4E       ; Gauge: Off
.draw    JMP C33D30      ; Redraw options

; Update sound mode
C33F21:  LDA #$20        ; Sound mode bit
         TRB $1D4E       ; Mode: Stereo
         BCS C33F36      ; If pushing right
         TDC             ; Volume: Stereo
         BRA C33F3_      ; Skip 2 lines
C33F36:  TSB $1D4E       ; Mode: Mono
         LDA #$FF        ; Volume: Mono
C33F3_:  JSR C33F46      ; Adjust volume
         JSR C30F0E      ; Sound: Cursor
         JMP C33D59      ; Redraw options

; Adjust volume based on sound mode (stereo = 0)
C33F46:  STA $001301     ; Set sound mode
         LDA #$F3        ; SPC code: $0D61
         STA $001300     ; Set SPC command
         JSL $C50004     ; Update ports
         RTS

; Update Cursor mode
C33F55:  LDA #$40        ; Cursor mode bit
         TRB $1D4E       ; Mode: Reset
         BCS C33F69      ; If pushing right
         JSR C34DE9      ; Forget positions
         BRA C33F6_      ; Redraw options
C33F69:  TSB $1D4E       ; Mode: Memory
         JSR C377FC      ; Reset positions
C33F6_:  JMP C33D84      ; Redraw options

; Update Reequip mode
C33F74:  LDA #$10        ; Reequip bit
         TRB $1D4E       ; Mode: Optimum
         BCC .draw       ; If pushing left
         TSB $1D4E       ; Mode: Empty
.draw    JMP C33DAF      ; Redraw options

; Update Button Settings mode
C33F8D:  LDA #$40        ; Btn.Set bit
         TRB $1D54       ; Mode: Normal
         BCC .draw       ; If pushing left
         TSB $1D54       ; Mode: Custom
.draw    JMP C33DDA      ; Redraw options

; Update Controller mode
C33FA6:  LDA #$80        ; Controller bit
         TRB $1D54       ; Mode: Single
         BCC .draw       ; If pushing left
         TSB $1D54       ; Mode: Multiple
.draw    JMP C33E0B      ; Redraw options

; Update Mag.Order
C33FBF:  LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         TRB $1D54       ; Clear in config
         BCC C33FD7      ; If pushing left

; Fork: Mag.Order +1
C33FCC:  CMP #$05        ; On "6"?
         BEQ C33FE0      ; Retain if so
         INC A           ; Order +1
         BRA C33FE0      ; Apply changes

; Fork: Mag.Order -1
C33FD7:  BEQ C33FE0      ; Retain if "1"
         DEC A           ; Order -1

; Fork: Apply Mag.Order
C33FE0:  TSB $1D54       ; Update config
         JMP C3411D      ; Redraw text

; Handle wallpaper selection
C33FED:  LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         TRB $1D4E       ; Clear in cofig
         BCC C34005      ; If pushing left

; Fork: Pushing right
C33FFA:  CMP #$07        ; On "8"?
         BEQ C3400E      ; Retain if so
         INC A           ; Skin number +1
         BRA C3400E      ; Apply changes

; Fork: Pushing left
C34005:  BEQ C3400E      ; Retain if "1"
         DEC A           ; Skin number -1

; Fork: Apply wallpaper
C3400E:  TSB $1D4E       ; Update config
         JSR C341CB      ; Redraw values
         JSR C33B5B      ; Refresh skin
         JMP C342A4      ; Draw RGB info

; Change viewed color in Config
C34021:  PHP             ; Save Carry
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         TRB $1D54       ; Clear in config
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         LSR A           ; Now 0-7
         PLP             ; Pushing right?
         BCC C3403C      ; Branch if not

; Fork: Move to next color
C34031:  CMP #$07        ; On last color?
         BEQ C34045      ; Retain if so
         INC A           ; Color number +1
         BRA C34045      ; Apply changes

; Fork: Move to preceding color
C3403C:  DEC A           ; Color number -1
         BPL C34045      ; Retain if > 0
         INC A           ; Color number +1

; Fork: Apply selection
C34045:  ASL A           ; Put in b1-b3
         ASL A           ; Put in b2-b4
         ASL A           ; Put in b3-b5
         TSB $1D54       ; Update config
         JSR C34214      ; Redraw arrow
         JMP C342A4      ; Draw RGB info

; Update red component of font or skin color
C3405C:  PEA $0002       ; Color index: 2
         BRA C3409_      ; Branch below

; Update green component of font or skin color
C3407B:  PEA $0001       ; Color index: 1
         BRA C3409_      ; Skip a line

; Update blue component of font or skin color
C3409A:  PEI ($00)       ; Color index: 0
C3409_:  PHP             ; Save Carry
         JSR C342DF      ; Separate RGB
         PLP             ; Pushing right?
         PLX             ; Comp index
         LDA $E0,X       ; Component
         BCC C340AD      ; Branch if left
         CMP #$1F        ; Comp = 31?
         BEQ C340B3      ; Branch if so
         INC $E0,X       ; Component +1
         BRA C340B3      ; Apply changes
C340AD:  BEQ C340B3      ; If comp = 0
         DEC $E0,X       ; Component -1
C340B3:  JSR C34302      ; Merge RGB
         BRA C340E4      ; Apply changes

; Apply player's font color
C340B9:  LDY $1D55       ; User font color
C340B_:  REP #$20        ; 16-bit A
         TYA             ; Color
         STA $7E304F     ; Set for FWF
         STA $7E3073     ; Set VWF color A
         STA $7E3077     ; Set VWF color B
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin colors after changes
C340CD:  LDX $00         ; Dst index: 0
         REP #$20        ; 16-bit A
C340D1:  LDA $1D57,Y     ; Player color
         STA $7E312B,X   ; Put in palette
         INY             ; Src index +1
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         CPX #$000E      ; Done 7 colors?
         BNE C340D1      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Apply player's skin or font colors after changes
C340E4:  TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C34112      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
;        CLC             ; Prepare ADC
         ADC $4216       ; Add product
         TAX             ; Index sum
         REP #$20        ; 16-bit A
         LDA $9A         ; Updated color
         STA $1D55,X     ; Set user color
         LDY $4216       ; Palette index
         JSR C340CD      ; Recolor skin
         BRA C3411A      ; Redraw RGB info

; Fork: Font
C34112:  LDY $9A         ; Updated color
         STY $1D55       ; Put in options
         JSR C340B9      ; Put in palettes
C3411A:  JMP C342A4      ; Redraw RGB info

; Draw Mag.Order settings
C3411D:  JSR C3880B      ; Color: Gray
         LDY #C34F7A     ; Text pointer
         JSR C302F9      ; Draw 1-6 in gray
         JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         PHA             ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3414F,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         PLA             ; Mag.Order
         JSR C341F7      ; Draw user value

; Fork: Draw all three spell types
C3415B:  TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         LDY #$0003      ; Strings: 3
C34169:  PHY             ; Save counter
         PHX             ; Save index
         JSR C34175      ; Draw string
         PLX             ; String index
         PLY             ; Strings left
         INX             ; Point to next
         DEY             ; One less left
         BNE C34169      ; Loop till last
         RTS

; Draw current Mag.Order spell type
C34175:  JSR wm9E8B      ; WRAM: 7E/9E8B
         PHY             ; Save pos index
         TDC             ; Clear A
         LDA.L C341B3,X  ; Text pointer
         TAX             ; Index it
         LDY #$0004      ; Letters: 4
.loop    LDA.L C34FA7,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE .loop       ; Loop till last
         REP #$20        ; 16-bit A
         PLA             ; String slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C341AD-2,X; Tilemap ptr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         JMP C387B_      ; Draw string

; Draw wallpaper values
C341CB:  JSR C3880B      ; Color: Gray
         LDY #C34F68     ; Text pointer
         JSR C302F9      ; Draw 1-8 in gray
         JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         PHA             ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C34204,X  ; Tilemap ptr
         TAX             ; Put in X
         SEP #$20        ; 8-bit A
         PLA             ; Skin number
C341F7:  CLC             ; Prepare ADC
         ADC.B #!num1    ; Convert to text
         STA $F9         ; Add to string
         STZ $FA         ; End string
         STX $F7         ; Set position
         LDY #$00F7      ; Source LBs
         TDC             ; Source HB
         JMP C302FD      ; Draw user value

; Draw wallpaper palette and arrow in Config
C34214:  LDA #$3C        ; Palette 7
         STA $29         ; Set tile info
         LDY #C34F9D     ; Text pointer
         JSR C302F9      ; Draw palette
         LDY #C3427E     ; Text pointer
         JSR C302F9      ; Erase arrow
         JSR C3880B      ; Color: Gray
         JSR C34260      ; Draw "Font"
         JSR C34267      ; Draw "Window"
         JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C34260      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         JSR C3D24D      ; Color: User's
         REP #$20        ; 16-bit A
         LDA.L C3426E-2,X; Text pointer
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         JSR C302F9      ; Draw arrow

; Fork: Draw "Window"
C34267:  LDY #C34F8F     ; Text pointer
         JMP C30326      ; Draw "Window"

; Fork: Draw "Font"
C34260:  LDY #C34F88     ; Text pointer
         JMP C302F9      ; Draw "Font"

; Draw RGB gauges and values in Config menu
C342A4:  JSR C33A24      ; Reset gauges
         LDA $1D4E       ; Game options
         AND #$0F        ; Get wallpaper
         XBA             ; Put in B
         LDA #$0E        ; Palette size
         JSR mul8        ; Skin x size
         LDA $1D54       ; Game options
         AND #$38        ; Viewed color
         BEQ C342C8      ; Branch if font
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         ADC $4216       ; Add product
         TAX             ; Index sum
         LDY $1D55,X     ; Skin color
         BRA C342CB      ; Skip a line
C342C8:  LDY $1D55       ; Font color
C342CB:  STY $9A         ; Memorize it
         JSR C342DF      ; Separate RGB
         JSR C34344      ; Draw B info
         JSR C342DF      ; Separate RGB
         JSR C34331      ; Draw G info
         JSR C342DF      ; Separate RGB
         BRA C3431E      ; Draw R info

; Separate RGB components for color in Config menu
C342DF:  LDA $9A         ; Color LB
         AND #$1F        ; Get red
         STA $E2         ; Memorize it
         LDA $9B         ; Color HB
         AND #$7C        ; Get blue
         LSR A           ; Shift bits
         LSR A           ; Now 0-31
         STA $E0         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $9A         ; Color
         AND #$03E0      ; Get green
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         LSR A           ; Now 0-31
         SEP #$20        ; 8-bit A
         STA $E1         ; Memorize it
         RTS

; Merge RGB components of updated color
C34302:  LDA $E0         ; Blue
         ASL A           ; x2
         ASL A           ; x4
         STA $E8         ; Memorize it
         LDA $E2         ; Red
         STA $E7         ; Memorize it
         TDC             ; Clear A
         LDA $E1         ; Green
         JSR x32r        ; x32
         ORA $E7         ; Add R&B
         STA $9A         ; Memorize it
         SEP #$20        ; 8-bit A
         RTS

; Draw value and fill gauge for red component
C3431E:  LDY #$452F      ; Tilemap ptr
         JSR C335E1      ; Set gauge pos
         LDA $E2         ; Red value
         LDX #$4529      ; Tilemap ptr
         BRA C34357      ; Draw text

; Draw value and fill gauge for green component
C34331:  LDY #$45AF      ; Tilemap ptr
         JSR C335E1      ; Set gauge pos
         LDA $E1         ; Green value
         LDX #$45A9      ; Tilemap ptr
         BRA C34357      ; Draw text

; Draw value and fill gauge for blue component
C34344:  LDY #$462F      ; Tilemap ptr
         JSR C335E1      ; Set gauge pos
         LDA $E0         ; Blue value
         LDX #$4629      ; Tilemap ptr

; Draw value and fill gauge for color component
C34357:  PHA             ; Save value
         PHA             ; Do it again
         PHX             ; Save position
         JSR C30563      ; Convert value
         PLX             ; Text position
         JSR C3D24D      ; Color: User's
         JSR C30539      ; Draw 2 digits
         JSR wm9E8B      ; WRAM: 7E/9E8B
         TDC             ; Clear A
         PLA             ; Color value
         LSR A           ; ÷2
         LSR A           ; ÷4
         TAX             ; Set counter
         BEQ C3437D      ; Branch if 0
C34375:  LDA.B #!bar8    ; Full tile char
         STA $2180       ; Add to string
         DEX             ; One less tile
         BNE C34375      ; Loop till last
C3437D:  PLA             ; Color component
         AND #$03        ; Extremity size
         TAX             ; Index it
         LDA.L C3439F,X  ; Partial tile
         STA $2180       ; Add to string
         STZ $2180       ; End string
         JSR txt30       ; Color: Gray
         JMP C38FD1      ; Draw gauge

; Text characters for filling color gauge
C3439F:  db !bar0        ; Empty tile
         db !bar2        ; 1/4 full
         db !bar4        ; 2/4 full
         db !bar6        ; 3/4 full

; 47: Initialize Cmd.Set menu
C343A3:  JSR C335F7      ; Reset/Stop stuff
         JSR C3450D      ; Draw menu
         LDY #C3476F     ; C3/476F
         JSR bg3v_       ; Set to shift text
         JSR C34697      ; Load navig data
         JSR C346A0      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$48        ; C3/43C0
         STA $27         ; Queue: Pick char
         JMP C33609      ; BRT:1 + NMI

; 48: Handle Cmd.Set menu member selection
C343C0:  JSR C3469D      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C343F1      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Selected member
         CMP #$04        ; Chose Arrange?
         BEQ C34407      ; Sort if so
         TAX             ; Index member
         LDA $69,X       ; Nobody there?
         BMI C343EB      ; Fail if so
         LDA $4E         ; Cursor row
         STA $64         ; Set member slot
         LDY #C3472B     ; C3/472B
         JSR C30681      ; Load navig data
         JSR C346BB      ; Relocate cursor
         LDA #$62        ; C3/4419
         STA $26         ; Next: Cmd choice
         JMP C30F1D      ; Sound: Click

; Fork: Play buzzer
C343EB:  JSR C3C5C6      ; Buzzer + Mosaic

; Fork: Handle B and Start
C343F1:  LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C34439      ; Exit if not
         LDA #$0D        ; C3/1CE3
         STA $27         ; Queue Config
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Reset command order
C34407:  JSR C30F1D      ; Sound: Click
         JSR C30FA4      ; Queue text upload
         JSR C344B1      ; Reset member 1
         JSR C344B9      ; Reset member 2
         JSR C344C2      ; Reset member 3
         JMP C344CB      ; Reset member 4

; 62: Handle Cmd.Set menu command choice 1
C34419:  JSR C346E3      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3443A      ; Branch if not
         LDA $4B         ; Cursor slot
         STA $28         ; Set blinker's
         JSR C32FA1      ; Create blinker
         LDA #$63        ; C3/4457
         STA $26         ; Next: Choice 2
         TDC             ; Clear A
         LDA $64         ; Selected member
         JSR C32DA_      ; Actor's address
         STY $67         ; Memorize it
         JMP C30F1D      ; Sound: Click
C34439:  RTS

; Fork: Handle B
C3443A:  LDA $09         ; Pushing B?
         BPL C34439      ; Exit if not
         JSR C34697      ; Load navig data
         LDA $64         ; Return position
         STA $4E         ; Set cursor row
         JSR C346A0      ; Relocate cursor
         LDA #$48        ; C3/43C0
         STA $26         ; Next: Pick char
         JMP C30F14      ; Sound: Cursor

; 63: Handle Cmd.Set menu command choice 2
C34457:  JSR C346E3      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3449E      ; Branch if not
         JSR C30F1D      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; Cursor's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $16,X       ; Second command
         PHA             ; Memorize it
         TDC             ; Clear A
         LDA $28         ; Blinker's slot
         REP #$21        ; 16-bit A; C-
         ADC $67         ; Add actor's adr
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $0016,Y     ; First command
         XBA             ; Move it to B
         PLA             ; Second command
         STA $0016,Y     ; Replace first
         XBA             ; First command
         STA $16,X       ; Replace second
         JSR C34595      ; Draw char 1 text
         JSR C345CE      ; Draw char 2 text
         JSR C34607      ; Draw char 3 text
         JSR C34640      ; Draw char 4 text
         JSR C30FA4      ; Queue text upload
         BRA C344A7      ; Next: Choice 1

; Fork: Handle B
C3449E:  LDA $09         ; Pushing B?
         BPL C344B0      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C344A7:  LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$62        ; C3/4419
         STA $26         ; Next: Choice 1
C344B0:  RTS

; Reset command list for member 1
C344B1:  LDX $00         ; Point to $6D
         JSR C344D4      ; Reset commands
         JMP C34595      ; Redraw text

; Reset command list for member 2
C344B9:  LDX #$0002      ; Point to $6F
         JSR C344D4      ; Reset commands
         JMP C345CE      ; Redraw text

; Reset command list for member 3
C344C2:  LDX #$0004      ; Point to $71
         JSR C344D4      ; Reset commands
         JMP C34607      ; Redraw text

; Reset command list for member 4
C344CB:  LDX #$0006      ; Point to $73
         JSR C344D4      ; Reset commands
         JMP C34640      ; Redraw text

; Reset member's battle command list
C344D4:  LDY $6D,X       ; Actor's address
         BEQ C3450C      ; Exit if nobody
         JSR gogo2       ; Gogo?
         BEQ C3450C      ; Exit if so
         XBA             ; Put actor in B
         LDA #$16        ; Actor data size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $ED7CA2,X   ; Commands 1+2
         STA $0016,Y     ; Set actor's
         LDA $ED7CA4,X   ; Commands 3+4
         STA $0018,Y     ; Set actor's
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
C3450C:  RTS

; Draw Cmd.Set menu
C3450D:  JSR C371BC      ; Clear BG2 map A
         LDX #C34571     ; C3/4571
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR txt30       ; Color: Blue
         LDY #C34FB3     ; Text pointer
         JSR C30326      ; Draw "Arrange"
         JSR C34595      ; Draw char 1 text
         JSR C345CE      ; Draw char 2 text
         JSR C34607      ; Draw char 3 text
         JSR C34640      ; Draw char 4 text
         JSR C30E93      ; Upload BG1 A+B
         JMP C30ED9      ; Upload BG3 A+B
C3463F:  RTS

; Draw Cmd.Set menu text for member 1
C34595:  LDA $69         ; Actor in slot
         BMI C3450C      ; Exit if none
         PEA $796D       ; Pos for cmd 1
         PEA $79E3       ; Pos for cmd 2
         PEA $79F7       ; Pos for cmd 3
         PEA $7A6D       ; Pos for cmd 4
         PEA $79CF       ; Pos for class
         PEA $794F       ; Pos for actor
         LDX $6D         ; Actor's address
         BRA C3464_      ; Draw text

; Draw Cmd.Set menu text for member 2
C345CE:  LDA $6A         ; Actor in slot
         BMI C3463F      ; Exit if none
         PEA $7B2D       ; Pos for cmd 1
         PEA $7BA3       ; Pos for cmd 2
         PEA $7BB7       ; Pos for cmd 3
         PEA $7C2D       ; Pos for cmd 4
         PEA $7B8F       ; Pos for class
         PEA $7B0F       ; Pos for actor
         LDX $6F         ; Actor's address
         BRA C3464_      ; Draw text

; Draw Cmd.Set menu text for member 3
C34607:  LDA $6B         ; Actor in slot
         BMI C3463F      ; Exit if none
         PEA $7CED       ; Pos for cmd 1
         PEA $7D63       ; Pos for cmd 2
         PEA $7D77       ; Pos for cmd 3
         PEA $7DED       ; Pos for cmd 4
         PEA $7D4F       ; Pos for class
         PEA $7CCF       ; Pos for actor
         LDX $71         ; Actor's address
         BRA C3464_      ; Draw text

; Draw Cmd.Set menu text for member 4
C34640:  LDA $6C         ; Actor in slot
         BMI C3463F      ; Exit if none
         PEA $7EAD       ; Pos for cmd 1
         PEA $7F23       ; Pos for cmd 2
         PEA $7F37       ; Pos for cmd 3
         PEA $7FAD       ; Pos for cmd 4
         PEA $7F0F       ; Pos for class
         PEA $7E8F       ; Pos for actor
         LDX $73         ; Actor's address
C3464_:  STX $67         ; Memorize it
         JSL $C20006     ; Load gear data
         JSR txt30       ; Color: Blue
         PLY             ; Text position
         JSR C3356A      ; Draw actor name
         JSR C3D24D      ; Color: User's
         PLY             ; Text position
         JSR C33580      ; Draw actor class
         PLY             ; Text position
cmdx4:   JSR C3468E      ; Draw command 4
         PLY             ; Text position
         JSR C34686      ; Draw command 3
         PLY             ; Text position
         JSR C3467F      ; Draw command 2
         PLY             ; Text position

; Draw member's 1st command
C34679:  JSR C335E1      ; Set pos/WRAM/Y
         BRA C34694      ; Draw command

; Draw member's 2nd command
C3467F:  JSR C335E1      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         BRA C34694      ; Draw command

; Draw member's 3rd command
C34686:  JSR C335E1      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         BRA C34694      ; Draw command

; Draw member's 4th command
C3468E:  JSR C335E1      ; Set pos/WRAM/Y
         INY             ; Point to cmd 2
         INY             ; Point to cmd 3
         INY             ; Point to cmd 4
C34694:  JMP C3653E      ; Draw command

; Load navigation data for Cmd.Set menu's actor list
C34697:  LDY #C346A6     ; C3/46A6
         JMP C30681      ; Load navig data

; Handle D-Pad for Cmd.Set menu's actor list
C3469D:  JSR C307B0      ; Handle D-Pad
C346A0:  LDY #C346AB     ; C3/46AB
         JMP C306C3      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list
C346BB:  TDC             ; Clear A
         LDA $64         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C346C3,X)  ; Relocate cursor

; Jump table for the above
C346C3:  dw C346CB       ; Member 1
         dw C346D1       ; Member 2
         dw C346D7       ; Member 3
         dw C346DD       ; Member 4

; Relocate cursor in Cmd.Set menu's command list for member 1
C346CB:  LDY #C34730     ; C3/4730
         JMP C306C3      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 2
C346D1:  LDY #C34738     ; C3/4738
         JMP C306C3      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 3
C346D7:  LDY #C34740     ; C3/4740
         JMP C306C3      ; Relocate cursor

; Relocate cursor in Cmd.Set menu's command list for member 4
C346DD:  LDY #C34748     ; C3/4748
         JMP C306C3      ; Relocate cursor

; Handle D-Pad and cursor for Cmd.Set menu's command list
C346E3:  JSR C346F6      ; Handle D-Pad
         TDC             ; Clear A
         LDA $64         ; Member
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C346EE,X)  ; Relocate cursor

; Jump table for the above
C346EE:  dw C346CB       ; Member 1
         dw C346D1       ; Member 2
         dw C346D7       ; Member 3
         dw C346DD       ; Member 4

; Handle D-Pad for Cmd.Set menu's command list
C346F6:  STZ $4D         ; Cursor col: 1st
         LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C34703      ; Branch if not
         STZ $4E         ; Cursor slot: Top
         JSR C30F0E      ; Sound: Cursor
C34703:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C34710      ; Branch if not
         LDA #$03        ; Slot: Bottom
         STA $4E         ; Set cursor slot
         JSR C30F0E      ; Sound: Cursor
C34710:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C3471D      ; Branch if not
         LDA #$01        ; Slot: Left
         STA $4E         ; Set cursor slot
         JSR C30F0E      ; Sound: Cursor
C3471D:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3476E      ; Exit if not
         LDA #$02        ; Slot: Right
         STA $4E         ; Set cursor slot
         JMP C30F0E      ; Sound: Cursor
C3476E:  RTS

; 49: Initialize Button Settings menu
C3478E:  JSR C335F7      ; Reset/Stop stuff
         JSR C34A2C      ; Draw menu
         LDY #C34AA3     ; C3/4AA3
         JSR bg3v_       ; Set to shift text
         LDY #C34AE3     ; C3/4AE3
         JSR C30681      ; Load navig data
         JSR C34ADD      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$4A        ; C3/47AB
         STA $27         ; Queue: Sustain
         JMP C33609      ; BRT:1 + NMI

; 4A: Sustain Button Settings menu
C347AB:  JSR C30FA4      ; Queue BG3 upload
         JSR C34ADA      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BEQ C347CB      ; Branch if not
         JSR C34D7C      ; Valid settings?
;        STA $E0         ; ...
         BNE C347DB      ; Fail if not
         JSR C3ADEF      ; Apply user keys
         LDA #$0D        ; C3/1CE3
         STA $27         ; Queue Config menu
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Fork: Handle left and right
C347CB:  LDA $0B         ; Semi-auto keys
         BIT #$03        ; Using left/right?
         BEQ C3476E      ; Exit if not
         JMP C34BF2      ; Handle changes

; Fork: Invalid combination
C347DB:  JMP C3C5C6      ; Buzzer + Mosaic

; 4B: Initialize Controller menu
C347E2:  JSR C335F7      ; Reset/Stop stuff
         JSR C3482A      ; Draw menu
         LDY #C349FC     ; C3/49FC
         JSR C33B2_      ; Queue Win2 HDMA
         LDY #C34A1B     ; C3/4A1B
         JSR C30681      ; Load navig data
         JSR C34A15      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$4C        ; C3/47FF
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; 4C: Sustain Controller menu
C347FF:  JSR C30FA4      ; Queue BG3 upload
         JSR C34A12      ; Handle D-Pad
         LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C3481B      ; Branch if not
         LDA #$0D        ; C3/1CE3
         STA $27         ; Queue Config menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor
C3481A:  RTS

; Fork: Handle left and right
C3481B:  LDA $0B         ; Semi-auto keys
         BIT #$03        ; Using left/right?
         BEQ C3481A      ; Exit if not
         TDC             ; Clear A
         LDA $4B         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Nobody there?
         BMI C3481A      ; Exit if so
         JSR C30F0E      ; Sound: Cursor
         TXA             ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3485F,X)  ; Apply changes

; Jump table for controller assignments
C3485F:  dw C34867       ; Member 1
         dw C34886       ; Member 2
         dw C348A7       ; Member 3
         dw C348C8       ; Member 4

; Draw Controller menu
C3482A:  LDX #C34A28     ; C3/4A28
         JSR C303C4      ; Draw menu window
         JSR C30EBD      ; Upload window
         JSR txt30       ; Color: Blue
         LDY #C34FBA     ; Text pointer
         JSR C302F9      ; Draw "Controller"
         JSR C348E9      ; Draw char 1 text
         JSR C34926      ; Draw char 2 text
         JSR C34963      ; Draw char 3 text
         JSR C349A0      ; Draw char 4 text
         JMP C30ED9      ; Upload text

; Update controller assignment for member 1
C34867:  LDA #$01        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3487C      ; Branch if not
         INC $1D4F       ; Assign Cntlr2
C3487C:  BRA C348E9      ; Redraw text

; Update controller assignment for member 2
C34886:  LDA #$02        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C34899      ; Branch if not
         LDA #$02        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C34899:  BRA C34926      ; Redraw text

; Update controller assignment for member 3
C348A7:  LDA #$04        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C348BD      ; Branch if not
         LDA #$04        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C348BD:  JMP C34963      ; Redraw text

; Update controller assignment for member 4
C348C8:  LDA #$08        ; Assign Cntlr1
         TRB $1D4F       ; Update settings
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C348DE      ; Branch if not
         LDA #$08        ; Assign Cntlr2
         TSB $1D4F       ; Update settings
C348DE:  JMP C349A0      ; Redraw text

; Draw Controller menu text for member 1
C348E9:  LDA $69         ; Nobody here?
         BMI C34962      ; Exit if so
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$7BCF      ; Text position
         JSR C3356A      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         LSR A           ; Player 1's?
         BCC C3490B      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34914      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C3491D      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C3490B:  LDA #$20        ; Color: User's
         JSR C34914      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C3491D      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34914:  STA $29         ; Set palette
         LDY #C34FC9     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C3491D:  STA $29         ; Set palette
         LDY #C34FD4     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Draw Controller menu text for member 2
C34926:  LDA $6A         ; Nobody here?
         BMI C34962      ; Exit if so
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$7C4F      ; Text position
         JSR C3356A      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$02        ; Player 1's?
         BEQ C34948      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C34951      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C3495A      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34948:  LDA #$20        ; Color: User's
         JSR C34951      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C3495A      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C34951:  STA $29         ; Set palette
         LDY #C34FDF     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C3495A:  STA $29         ; Set palette
         LDY #C34FEA     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"
C34962:  RTS

; Draw Controller menu text for member 3
C34963:  LDA $6B         ; Nobody here?
         BMI C34962      ; Exit if so
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$7CCF      ; Text position
         JSR C3356A      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$04        ; Player 1's?
         BEQ C34985      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C3498E      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C34997      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C34985:  LDA #$20        ; Color: User's
         JSR C3498E      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C34997      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C3498E:  STA $29         ; Set palette
         LDY #C34FF5     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C34997:  STA $29         ; Set palette
         LDY #C35000     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Draw Controller menu text for member 4
C349A0:  LDA $6C         ; Nobody here?
         BMI C34962      ; Exit if so
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$7D4F      ; Text position
         JSR C3356A      ; Draw actor name
         LDA $1D4F       ; Assigned pad
         AND #$08        ; Player 1's?
         BEQ C349C2      ; Branch if so
         LDA #$24        ; Color: Gray
         JSR C349CB      ; Draw "Cntlr1"
         LDA #$20        ; Color: User's
         BRA C349D4      ; Draw "Cntlr2"

; Fork: Highlight Cntlr1
C349C2:  LDA #$20        ; Color: User's
         JSR C349CB      ; Draw "Cntlr1"
         LDA #$24        ; Color: Gray
         BRA C349D4      ; Draw "Cntlr2"

; Fork: Draw "Cntlr1"
C349CB:  STA $29         ; Set palette
         LDY #C3500B     ; Text pointer
         JMP C302F9      ; Draw "Cntlr1"

; Fork: Draw "Cntlr2"
C349D4:  STA $29         ; Set palette
         LDY #C35016     ; Text pointer
         JMP C302F9      ; Draw "Cntlr2"

; Window 2 positions per scanline for Controller menu
C349FC:  db $27,$FF,$FF  ; 255, 255
         db $30,$08,$F7  ; 8, 247
         db $68,$FF,$FF  ; 255, 255
         db $10,$08,$F7  ; 8, 247
         db $10,$FF,$FF  ; 255, 255
         db $00          ; End

; Handle D-Pad for Controller menu
C34A12:  JSR C307B0      ; Handle D-Pad
C34A15:  LDY #C34A20     ; C3/4A20
         JMP C306C3      ; Relocate cursor

; Draw Button Settings menu
C34A2C:  LDX #C34A7C     ; C3/4A7C
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR C3D252      ; Color: Blue
         LDX #C35021     ; Text ptrs loc
         LDA #$08        ; Strings: 8
         JSR C3714E      ; Draw title, etc.
         LDX #C35031     ; Text ptrs loc
         LDA #$07        ; Strings: 7
         JSR C3712C      ; Draw key names
         JSR C34AF6      ; Draw A options
         JSR C34B22      ; Draw B options
         JSR C34B44      ; Draw X options
         JSR C34B68      ; Draw Y options
         JSR C34B8A      ; Draw L options
         JSR C34BAE      ; Draw R options
         JSR C34BD0      ; Draw S options
         JSR C30E93      ; Upload BG1 A+B
         JMP C30ED9      ; Upload text

; Handle D-Pad for Button Settings menu
C34ADA:  JSR C307B0      ; Handle D-Pad
C34ADD:  LDY #C34AE8     ; C3/4AE8
         JMP C306C3      ; Relocate cursor

; Draw options for A in button settings
C34AF6:  JSR C3658A      ; Color: Gray
         LDX #C3503F     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D50       ; Game options
         AND #$F0        ; Action for A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3503F-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Draw options for B in button settings
C34B22:  JSR C3658A      ; Color: Gray
         LDX #C3504B     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D50       ; Game options
         AND #$0F        ; Action for B
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3504B-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Draw options for X in button settings
C34B44:  JSR C3658A      ; Color: Gray
         LDX #C35057     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D51       ; Game options
         AND #$F0        ; Action for X
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C35057-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Draw options for Y in button settings
C34B68:  JSR C3658A      ; Color: Gray
         LDX #C35063     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D51       ; Game options
         AND #$0F        ; Action for Y
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C35063-2,X; Text pointer
C34B17:  TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         JSR C3D24D      ; Color: User's
         JMP C30326      ; Draw lit option

; Draw options for L in button settings
C34B8A:  JSR C3658A      ; Color: Gray
         LDX #C3506F     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D52       ; Game options
         AND #$F0        ; Action for L
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3506F-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Draw options for R in button settings
C34BAE:  JSR C3658A      ; Color: Gray
         LDX #C3507B     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D52       ; Game options
         AND #$0F        ; Action for R
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3507B-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Draw options for Select in button settings
C34BD0:  JSR C3658A      ; Color: Gray
         LDX #C35087     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw all in gray
         TDC             ; Clear A
         LDA $1D53       ; Game options
         AND #$0F        ; Action for SEL...
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C35087-2,X; Text pointer
         BRA C34B17      ; Draw lit option

; Handle changes in Button Settings menu
C34BF2:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C34BFA,X)  ; Apply changes

; Jump table for the above
C34BFA:  dw C34C08       ; A
         dw C34C44       ; B
         dw C34C74       ; X
         dw C34CB0       ; Y
         dw C34CE0       ; L
         dw C34D1C       ; R
         dw C34D4C       ; Select

; Update action assigned to the A button
C34C08:  LDA $1D50       ; Game options
         AND #$F0        ; Action for A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34C24      ; Branch if so

; Fork: Pushing right
C34C19:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34C2E      ; Exit if so
         INC $E0         ; Move right
         BRA C34C2F      ; Apply changes
C34C2E:  RTS

; Fork: Pushing left
C34C24:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34C2E      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34C2F:  LDA $E0         ; Chosen action
         ASL A           ; Put in b1-b4
         ASL A           ; Put in b2-b5
         ASL A           ; Put in b3-b6
         ASL A           ; Put in b4-b7
         STA $E0         ; Save changes
         LDA $1D50       ; Game options
         AND #$0F        ; Clear A action
         ORA $E0         ; Set chosen one
         STA $1D50       ; Save changes
         JMP C34AF6      ; Redraw options

; Update action assigned to the B button
C34C44:  LDA $1D50       ; Game options
         AND #$0F        ; Action for B
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34C5C      ; Branch if so

; Fork: Pushing right
C34C51:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34C66      ; Exit if so
         INC $E0         ; Move right
         BRA C34C67      ; Apply changes
C34C66:  RTS

; Fork: Pushing left
C34C5C:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34C66      ; Exit if so
         DEC $E0         ; Move right

; Fork: Apply changes
C34C67:  LDA $1D50       ; Game options
         AND #$F0        ; Clear B action
         ORA $E0         ; Set chosen one
         STA $1D50       ; Save changes
         JMP C34B22      ; Redraw options

; Update action assigned to the X button
C34C74:  LDA $1D51       ; Game options
         AND #$F0        ; Action for X
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34C90      ; Branch if so

; Fork: Pushing right
C34C85:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34C9A      ; Exit if so
         INC $E0         ; Move right
         BRA C34C9B      ; Apply changes
C34C9A:  RTS

; Fork: Pushing left
C34C90:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34C9A      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34C9B:  LDA $E0         ; Chosen action
         ASL A           ; Put in b1-b4
         ASL A           ; Put in b2-b5
         ASL A           ; Put in b3-b6
         ASL A           ; Put in b4-b7
         STA $E0         ; Save changes
         LDA $1D51       ; Game options
         AND #$0F        ; Clear X action
         ORA $E0         ; Set chosen one
         STA $1D51       ; Save changes
         JMP C34B44      ; Redraw options

; Update action assigned to the Y button
C34CB0:  LDA $1D51       ; Game options
         AND #$0F        ; Action for Y
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34CC8      ; Branch if so

; Fork: Pushing right
C34CBD:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34CD2      ; Exit if so
         INC $E0         ; Move right
         BRA C34CD3      ; Apply changes
C34CD2:  RTS

; Fork: Pushing left
C34CC8:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34CD2      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34CD3:  LDA $1D51       ; Game options
         AND #$F0        ; Clear Y action
         ORA $E0         ; Set chosen one
         STA $1D51       ; Save changes
         JMP C34B68      ; Redraw options

; Update action assigned to the L button
C34CE0:  LDA $1D52       ; Game options
         AND #$F0        ; Action for L
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34CFC      ; Branch if so

; Fork: Pushing right
C34CF1:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34D06      ; Exit if so
         INC $E0         ; Move right
         BRA C34D07      ; Apply changes
C34D06:  RTS

; Fork: Pushing left
C34CFC:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34D06      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34D07:  LDA $E0         ; Chosen action
         ASL A           ; Put in b1-b4
         ASL A           ; Put in b2-b5
         ASL A           ; Put in b3-b6
         ASL A           ; Put in b4-b7
         STA $E0         ; Save changes
         LDA $1D52       ; Game options
         AND #$0F        ; Clear L action
         ORA $E0         ; Set chosen one
         STA $1D52       ; Save changes
         JMP C34B8A      ; Redraw options

; Update action assigned to the R button
C34D1C:  LDA $1D52       ; Game options
         AND #$0F        ; Action for L
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34D34      ; Branch if so

; Fork: Pushing right
C34D29:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34D3E      ; Exit if so
         INC $E0         ; Move right
         BRA C34D3F      ; Apply changes
C34D3E:  RTS

; Fork: Pushing left
C34D34:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34D3E      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34D3F:  LDA $1D52       ; Game options
         AND #$F0        ; Clear R action
         ORA $E0         ; Set chosen one
         STA $1D52       ; Save changes
         JMP C34BAE      ; Redraw options

; Update action assigned to Select
C34D4C:  LDA $1D53       ; Game options
         AND #$0F        ; Action for SEL
         STA $E0         ; Memorize it
         LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing left?
         BCC C34D64      ; Branch if so

; Fork: Pushing right
C34D59:  LDA $E0         ; Lit option
         CMP #$06        ; Rightmost?
         BEQ C34D6E      ; Exit if so
         INC $E0         ; Move right
         BRA C34D6F      ; Apply changes
C34D6E:  RTS

; Fork: Pushing left
C34D64:  LDA $E0         ; Lit option
         DEC A           ; Leftmost?
         BEQ C34D6E      ; Exit if so
         DEC $E0         ; Move left

; Fork: Apply changes
C34D6F:  LDA $1D53       ; Game options
         AND #$F0        ; Clear SEL action
         ORA $E0         ; Set chosen one
         STA $1D53       ; Save changes
         JMP C34BD0      ; Redraw options

; Validate changes made in Button Settings menu
C34D7C:  LDA $1D50       ; Game options
         AND #$0F        ; Action for B
         STA $7E9D89     ; Add to buffer
         LDA $1D50       ; Game options
         AND #$F0        ; Action for A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $7E9D8A     ; Add to buffer
         LDA $1D51       ; Game options
         AND #$0F        ; Action for Y
         STA $7E9D8B     ; Add to buffer
         LDA $1D51       ; Game options
         AND #$F0        ; Action for X
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $7E9D8C     ; Add to buffer
         LDA $1D52       ; Game options
         AND #$0F        ; Action for R
         STA $7E9D8D     ; Add to buffer
         LDA $1D52       ; Game options
         AND #$F0        ; Action for L
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         LSR A           ; Now 0-7
         STA $7E9D8E     ; Add to buffer
         LDA $1D53       ; Game options
         AND #$0F        ; Action for SEL
         STA $7E9D8F     ; Add to buffer

; Fork: Check if all actions are assigned
C34DC7:  LDA #$01        ; 1st: Confirm
         STA $E0         ; Set cur action
         LDY $00         ; Actions done: 0

; Fork: Check if current action is assigned
C34DCD:  LDX $00         ; 1st key: A
C34DCF:  LDA $7E9D89,X   ; Key's action
         CMP $E0         ; Matches ours?
         BEQ C34DDF      ; Branch if so
         INX             ; Key index +1
         CPX #$0007      ; Done all 7?
         BNE C34DCF      ; Loop if not
         TXA             ; Valid: N
         RTS

; Fork: Check next action
C34DDF:  INC $E0         ; Action num +1
         INY             ; One more done
         CPY #$0006      ; Done all 6?
         BNE C34DCD      ; Loop if not
         TDC             ; Valid: Y
         RTS

; Forget memorized cursor positions for main menu
C34DE9:  LDX #$001E      ; Position index
C34DEB:  STZ $022B,X     ; Clear position
         DEX             ; Index -1
         BPL C34DEB      ; Loop till < 0
         RTS

; Load navigation data for Skills menu
C35213:  LDY #C35232     ; C3/5232
         JMP C30681      ; Load navig data

; Handle D-Pad and cursor memory for Skills menu
C35219:  JSR C307B0      ; Handle D-Pad
C3521C:  LDY #C35237     ; C3/5237
         JSR C306C3      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $4D         ; Cursor position
         STA $0236,X     ; Remember it
         SEP #$20        ; 8-bit A
         RTS

; Load navigation data for Magic menu
C35245:  LDY #C3526C     ; C3/526C
         JMP C30681      ; Load navig data

; Handle D-Pad and cursor memory for Magic menu
C3524B:  JSR C38948      ; Handle D-Pad
C3524E:  LDY #C35271     ; C3/5271
         JSR C306CB      ; Relocate cursor
         TDC             ; Clear A
         LDA $28         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $4F         ; List column
         STA $023E,X     ; Remember it
         LDA $50         ; List row
         STA $023F,X     ; Remember it
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $4A         ; Scroll position
         STA $0246,X     ; Remember it
         RTS

; Load navigation data for SwdTech, Blitz, or Dance menu
C352A7:  LDY #C352B8     ; C3/52B8
         JMP C30681      ; Load navig data

; Handle D-Pad for SwdTech, Blitz, or Dance menu
C352AD:  JSR C307B0      ; Handle D-Pad
C352B0:  LDY #C352BD     ; C3/52BD
         JMP C306C3      ; Relocate cursor

; Load navigation data for Lore or Espers menu
C352CD:  LDY #C352DC     ; C3/52DC
         JMP C30681      ; Load navig data

; Handle D-Pad for Lore or Espers menu
C352D3:  JSR C38948      ; Handle D-Pad
C352D6:  LDY #C352E1     ; C3/52E1
         JMP C306CB      ; Relocate cursor

; Handle D-Pad for Rage menu
C3530B:  JSR C38948      ; Handle D-Pad
C3530E:  LDY #C35319     ; C3/5319
         JMP C306CB      ; Relocate cursor

; Draw Skills menu, disable individual MP costs in Magic menu
C3533D:  STZ $9E         ; No MP by Magic
         JSR C30FF4      ; Stop VRAM DMA B
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         JSR bg2b_cl     ; Clear BG2 A+B
         LDX #C3545E     ; C3/545E
         JSR boxes_      ; Upload windows
         JSR C353E7      ; Draw actor info
         JSR C30E93      ; Upload BG1 A+B
         JSR bg3c_cl     ; Clear BG3 A-C
         JSR C3AFC5      ; Build desc map
         JSR C3AE9A      ; Upload tech names
         JSR C353FD      ; Set skill colors
         LDX #$0006      ; 1st: Dance
.loop    PHX             ; Save skill index
         LDA $79,X       ; Text palette
         STA $29         ; Set attributes
         REP #$20        ; 16-bit A
         TXA             ; Skill index
         ASL A           ; Double it
         TAX             ; Reindex it
         LDA.L skillnm,X ; Text pointer
         TAY             ; Put it in Y
         JSR C30326      ; Draw skill name
         PLX             ; Skill index
         DEX             ; Skill index -1
         BPL .loop       ; Loop till < 0
         JMP C30ED9      ; Upload BG3 A+B

; Draw actor info in Skills menu, including blue text
C353E7:  JSR bg1b_cl     ; Clear BG1 A+B
         JSR C3658A      ; Color: Blue
         LDX #C362D6     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         JMP C355B4      ; Draw actor info

; Assign a palette to each submenu in Skills menu
C353FD:  LDA #$24        ; Gray palette
         LDX #$0006      ; 1st: Dance
C35401:  STA $79,X       ; Disable menu
         DEX             ; Menu slot -1
         BPL C35401      ; Loop till Espers
         JSR C32D9E      ; Actor's address
         LDX #$0004      ; Commands: 4
C35410:  PHX             ; Save counter
         LDX #$0006      ; 1st: Dance
C35413:  LDA $0016,Y     ; Actor's command
         CMP.L C35438,X  ; Unlocks submenu?
         BNE C35420      ; Skip menu if not
         LDA #$20        ; Color: User's
         STA $79,X       ; Enable menu
C35420:  DEX             ; Menu slot -1
         BPL C35413      ; Loop till Espers
         INY             ; Cmd slot +1
         PLX             ; Loop counter
         DEX             ; One less cmd
         BNE C35410      ; Loop till last
         JSR gogo1       ; Actor = Gogo?
         BNE C35437      ; Exit if not
         LDA #$24        ; Gray palette
         STA $79         ; Disable Espers
C35437:  RTS

; Battle commands that unlock a skill menu
C35438:  db $02          ; Magic (unlocks Espers)
         db $02          ; Magic (unlocks Magic)
         db $07          ; SwdTech
         db $0A          ; Blitz
         db $0C          ; Lore
         db $10          ; Rage
         db $13          ; Dance

; Draw Magic list and blue "MP.." and create portrait
C3543F:  JSR C371A9      ; Clear BG1 map A
         JSR C355EB      ; Build spell list
         JSR C35659      ; Draw spell list
         JSR C3D252      ; Color: Blue
         LDY #C362DC     ; Text pointer
         JSR C302F9      ; Erase title diac.
         LDY #C362E5     ; Text pointer
         JSR C302F9      ; Draw "MP.."
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Set to condense text in Skills menu or submenu
C35482:  LDY #C354EC     ; C3/54EC
         JSR bg3v_       ; Queue BG3 V-Pan
         JSR C354F3      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C354A5:  LDA.L C35538,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         DEX             ; Index -1
         BPL C354A5      ; Loop till < 0
         LDY #$9A09      ; Src: 7E/9A09
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load vertical shift values for BG1 text in skill menus
C354F3:  LDX $00         ; Index: 0
C354F5:  LDA.L C35545,X  ; Stats V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At skills?
         BNE C354F5      ; Loop if not
C35503:  LDA.L C35545,X  ; Skill V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C35545,X  ; Add V-Data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0063      ; Past list?
         BNE C35503      ; Loop if not
C35529:  LDA.L C35545,X  ; Bottom V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0067      ; End of table?
         BNE C35529      ; Loop if not
         RTS

; Draw actor info in Skills menu
C355B4:  JSR C32D9E      ; Actor's address
         STY $67         ; Memorize it
C355BC:  LDY #$42DB      ; Class/KO pos
         LDX #$4748      ; Icon position
         JSR C334C2      ; Do class/status
         LDY #C36333     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C36337     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C355E1     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
C355D7:  JSR C3D24D      ; Color: User's
         LDY #$41DB      ; Text position
         JMP C335AE      ; Draw held esper

; Build Magic list based on Mag.Order
C355EB:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX #$003C      ; Slots: 60
         LDA #$FF        ; Spell: None
C355F6:  STA $2180       ; Add to list
         DEX             ; One less spell
         BNE C355F6      ; Loop till last
         TDC             ; Clear A
         TAY             ; List slot: 1
         LDA $1D54       ; Game options
         AND #$07        ; Get Mag.Order
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
C35606:  PHX             ; Save index
         LDA.L C35618,X  ; Starting spell
         CMP #$FF        ; At terminator?
         BEQ C35616      ; Exit if so
         JSR C35630      ; Populate list
         PLX             ; Type index
         INX             ; Index +1
         BRA C35606      ; Do next type
C35616:  PLX             ; Unstack index
         RTS

; Starting spell for each Magic type, sorted based on Mag.Order
C35618:  db $2D,$00,$18,$FF  ; 1: Cure, Fire, Scan
         db $2D,$18,$00,$FF  ; 2: Cure, Scan, Fire
         db $00,$18,$2D,$FF  ; 3: Fire, Scan, Cure
         db $00,$2D,$18,$FF  ; 4: Fire, Cure, Scan
         db $18,$2D,$00,$FF  ; 5: Scan, Cure, Fire
         db $18,$00,$2D,$FF  ; 6: Scan, Fire, Cure

; Add spells of given type to Magic list based on starting spell
C35630:  LDX #$0018      ; Black spells: 24
         CMP #$00        ; Base = Fire?
         BEQ C35647      ; Branch if so
         LDX #$0009      ; White spells: 9
         CMP #$2D        ; Base = Cure?
         BEQ C35647      ; Branch if so
         LDX #$0015      ; Gray spells: 21

; Fork: Populate list
C35647:  STX $E0         ; Set spells left
C3564A:  TYX             ; List slot
         STA $7E9D89,X   ; Add spell there
         INC A           ; Spell number +1
         INY             ; List slot +1
         DEC $E0         ; One less spell
         BNE C3564A      ; Loop till last

; Fork: Skip a row to add a separator
C35655:  INY             ; List slot +1
         INY             ; List slot +1
         INY             ; List slot +1
         RTS

; Draw Magic list
C35659:  JSR C38B78      ; Define $E5, $E6
         LDA #$09        ; Rows left: 9
C3565F:  PHA             ; Save counter
         JSR C35670      ; Draw 3 spells
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C3565F      ; Loop till last
         RTS

; Draw a row of three spells in Magic menu
C35670:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw spell A
         LDX #$000C      ; X: 12
         JSR .recur      ; Draw spell B
         LDX #$0015      ; X: 21
.recur   JSR C35692      ; Define source
         JSR C356A1      ; Draw spell C
         INC $E5         ; Menu slot +1
         RTS

; Set source for loading Magic name
C35692:  LDY.W #!mag_ns  ; Letters: 5
         STY $EB         ; Set src size
         LDY.W #!mag_np  ; ED/7400
         STY $EF         ; Set src LBs
         LDA.B #!mag_np!h; Bank: ED
         STA $F1         ; Set src HB
         RTS

; Draw text in spell slot of Magic menu
C356A1:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         LDA $9E         ; Show MP in list?
         BEQ C35715      ; Branch if not
         JSR C357BB      ; Spell
         JSR C3581C      ; Handle graying
         JSR C357BB      ; Spell
         BEQ C356F1      ; Blank if none
         JSR C35771      ; Spell mastery
         INC A           ; Fully learned?
         BNE C356F1      ; Blank if not

; Fork: Draw spell plus MP cost
C356C7:  JSR C357BB      ; Spell
         JSR C38BF2      ; Load name
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JSR C357BB      ; Spell
         JSR C357DC      ; Define MP cost
         JMP draw2n      ; Draw string

; Fork: Blank spell slot
C356F1:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA #$FF        ; Spell: None
         STA $7E9D89,X   ; Assign to slot
         JSR C35888      ; Disable spell
         LDY.W #!mag_ns+3; Spaces: 8
         JMP spacedr     ; Draw 8 spaces

; Fork: Draw spell plus percentage
C35715:  JSR C357BB      ; Spell
         BEQ C356F1      ; Blank if none
         JSR C35771      ; Spell mastery
         CMP #$00        ; Zero?
         BEQ C356F1      ; Blank if so
         PHA             ; Memorize it
         JSR C357BB      ; Spell
         JSR C38BF2      ; Load name
         PLA             ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C3575A      ; Branch if so
         JSR C30563      ; Turn into text
         JSR C35888      ; Disable spell
         JSR C3D252      ; Color: Bluish
         JSR add2n       ; Add mastery
         LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C35754:  JMP C387B_      ; Draw string

; Fork: Draw spell name only
C3575A:  JSR C357BB      ; Spell
         JSR C3581C      ; Handle graying
         LDY #$0003      ; Spaces: 3
         JSR spaces      ; Add to string
         BRA C35754      ; Draw string

; Get spell's mastery percentage
C35771:  STA $E0         ; Save spell
         JSR gogo1       ; Actor = Gogo?
         BEQ C35794      ; Branch if so
C3577D:  XBA             ; Put in B
         LDA #$36        ; Spell list size
         JSR mul8        ; Actor x size
         TDC             ; Clear A
         LDA $E0         ; Spell
         REP #$20        ; 16-bit A
         ADC $4216       ; Add product
         TAX             ; Index sum
         SEP #$20        ; 8-bit A
         LDA $1A6E,X     ; Spell mastery
         RTS

; Fork: Test all members for Gogo
C35794:  TDC             ; Member slot: 1
C35796:  STA $E1         ; Save cur member
         JSR C32DA_      ; Actor's address
         BEQ C357B1      ; Skip if nobody
         JSR gogo2       ; Gogo or higher?
         BCS C357B1      ; Skip if so
         JSR C3577D      ; Actor's mastery
         CMP #$FF        ; Fully learned?
         BEQ C357BA      ; Exit if so
C357B1:  TDC             ; Clear A
         LDA $E1         ; Member slot
         INC A           ; Member slot +1
         CMP #$04        ; Done all 4?
         BNE C35796      ; Loop if not
         TDC             ; Mastery: 0
C357BA:  RTS

; Get processed list entry
C357BB:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Spell in slot
         CMP #$FF        ; Empty slot?
         RTS

; Compute spell data index
C357C4:  XBA             ; Put spell in B
         LDA #$0E        ; Data size
         JSR mul8        ; Spell x size
         TAX             ; Index product
         TDC             ; Clear A
         RTS

; Define spell's MP cost
C357DC:  PHA             ; Save spell
         JSR C357C4      ; Compute index
         LDA $C46AC5,X   ; Base MP cost
         STA $E0         ; Memorize it

; Fork: Step Mine
C357E9:  PLA             ; Spell
         CMP #$99        ; Step Mine?
         BNE C357FD      ; Branch if not
         LDA $021B       ; Hours played
         ASL A           ; Double them
         STA $E0         ; Set MP cost
         LDA $021C       ; Minutes played
         CMP #$1E        ; Under 30?
         BCC C357FD      ; Branch if so
         INC $E0         ; MP cost +1

; Fork: Economizer
C357FD:  LDA $11D7       ; Gear effects
         ASL A           ; Economizer's?
         BPL C35809      ; Branch if not
         LDA #$01        ; MP cost: 1
         BRA C3581A      ; Put it in X

; Fork: Gold Hairpin
C35809:  ASL A           ; Gold Hairpin?
         BPL C35817      ; Branch if not
         LDA $E0         ; MP cost
         INC A           ; Add one
         LSR A           ; Halve it
         BRA C3581A      ; Put it in X

; Fork: Normal MP cost
C35817:  LDA $E0         ; Base MP cost
C3581A:  TAX             ; Put it in X
         RTS

; Enable or disable spell in Magic menu
C3581C:  CMP #$2A        ; Warp?
         BEQ C3584A      ; Branch if so
C35824:  JSR C357C4      ; Compute index
         LDA $C46AC3,X   ; Spell properties
         LSR A           ; Usable in field?
         BCC C35888      ; Disable if not
         JSR C357BB      ; Spell
         JSR C357DC      ; Define MP cost
         BRA C35857      ; Test MP and Imp

; Fork: Warp
C3584A:  STA $E3         ; Memorize spell
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C35888      ; Disable if not
         LDA $E3         ; Spell number
         BRA C35824      ; Do basic checks

; Fork: Test Imp
C35857:  STX $E2         ; Save MP cost
         JSR C32D9E      ; Define Y
         LDA $0014,Y     ; Actor's status
         AND #$20        ; Imp?
         BEQ C3586A      ; Branch if not
         JSR C357BB      ; Spell
         CMP #$23        ; Imp?
         BNE C35888      ; Disable if not

; Fork: Test MP
C3586A:  LDX $0D,Y       ; Actor's MP
         CPX $E2         ; Below cost?
         BCC C35888      ; Disable if so

; Fork: Enable spell
C3587B:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         JSR C3D24D      ; Color: User's
         BRA C3588_      ; Enable spell

; Fork: Disable spell
C35888:  TDC             ; Clear A
         LDA $E5         ; Spell slot
         TAX             ; Index it
         JSR C3880B      ; Color: Gray
C3588_:  STA $7E9E09,X   ; Disable spell
         RTS

; Draw MP cost in corner of Magic menu
C35895:  JSR C3D24D      ; Color: User's
         LDY #$80D3      ; Tilemap ptr
         JSR C335E1      ; Set position
         JSR C3CF1D      ; Spell by cursor
         JSR C357DC      ; Define MP cost
draw2n:  JSR C30563      ; Turn into text
draw2n_: JSR add2n       ; Add to string
         JMP C387B_      ; Draw MP cost

; Draw Lore list and menu title, create portrait
C358C8:  JSR C371A9      ; Clear BG1 map A
         JSR C3590B      ; Draw Lore list
         JSR C3D252      ; Color: Blue
         LDY #C362EE     ; Text pointer
         JSR C30326      ; Draw "Lore"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Build Lore list
C358DE:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; Index: 0
         STZ $E0         ; 1st: Condemned
C358E8:  LDY #$0008      ; Lores left: 8
         LDA $1D29,X     ; 8 known lores
C358EE:  ROR A           ; Got current?
         PHA             ; Save 8 lores
         BCC C358F9      ; Blank if not
         LDA $E0         ; Lore number
         BRA C358FB      ; Skip a line
C358F9:  LDA #$FF        ; Esper: None
C358FB:  STA $2180       ; Add to list
         INC $E0         ; Lore number +1
         PLA             ; 8 known lores
         DEY             ; Lores left -1
         BNE C358EE      ; Loop till last
         INX             ; Point to next 8
         CPX #$0003      ; Done 24 lores?
         BNE C358E8      ; Loop if not
         RTS

; Build and draw Lore list
C3590B:  JSR C358DE      ; Build Lore list
         JSR C38B78      ; Define $E5, $E6
         LDA #$09        ; Lores left: 9
C35914:  PHA             ; Save counter
         JSR C35925      ; Draw Lore row
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Lores left
         DEC A           ; One less left
         BNE C35914      ; Loop till last
         RTS

; Draw a row of two Lore names, includng MP cost
C35925:  JSR C3D24D      ; Color: User's
         LDX #$0003      ; X: 3
         JSR .recur      ; Draw Lore A
         LDX #$0011      ; X: 17
.recur   JSR C35940      ; Define source
         JSR C3594F      ; Draw Lore B
         INC $E5         ; Lore slot +1
         RTS

; Set source for loading Lore name
C35940:  LDY.W #!lor_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!lor_np  ; ED/77B6
         STY $EF         ; Set src LBs
         LDA.B #!lor_np!h; Bank: ED
         STA $F1         ; Set src HB
         RTS

; Draw Lore's name and MP cost
C3594F:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Lore in slot
         BEQ C35999      ; Blank if none
         TXA             ; Lore slot
         JSR C38BF2      ; Load name
         LDA.B #!2dot    ; Char: ".."
         STA $2180       ; Add to string
         LDA $E5         ; Lore slot
         CLC             ; Prepare ADC
         ADC #$8B        ; Get attack ID
         JSR C357DC      ; Define MP cost
         JMP draw3n      ; Draw string

; Fork: Blank Lore slot
C35999:  LDY.W #!lor_ns+4; Spaces: 12
         JMP spacedr     ; Draw 12 spaces

; Draw SwdTech list and menu title, create portrait
C359B0:  JSR C371A9      ; Clear BG1 map A
         JSR C359C9      ; Build tech list
         JSR C3AE09      ; And its tilemap
         JSR C3D252      ; Color: Blue
         LDY #C3631B     ; Text pointer
         JSR C30326      ; Draw "SwdTech"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Draw Rage list and menu title, create portrait
C359EC:  JSR C371A9      ; Clear BG1 map A
         JSR C35A02      ; Draw Rage list
         JSR C3D252      ; Color: Blue
         LDY #C362F7     ; Text pointer
         JSR C30326      ; Draw "Rage"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Build and draw Rage list
C35A02:  JSR C35A1C      ; Build Rage list
         JSR C38B78      ; Define $E5, $E6
         LDA #$09        ; Rows left: 9
C35A0B:  PHA             ; Save counter
         JSR C35A49      ; Draw 2 Rages
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35A0B      ; Loop till last
         RTS

; Build Rage list
C35A1C:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Guard
C35A26:  LDY #$0008      ; Rages left: 8
         LDA $1D2C,X     ; 8 known Rages
C35A2C:  ROR A           ; Got current?
         PHA             ; Save 8 Rages
         BCC C35A37      ; Blank if not
         LDA $E0         ; Rage number
         BRA C35A39      ; Skip a line
C35A37:  LDA #$FF        ; Rage: None
C35A39:  STA $2180       ; Add to list
         INC $E0         ; Rage number +1
         PLA             ; 8 known Rages
         DEY             ; Rages left -1
         BNE C35A2C      ; Loop till last
         INX             ; Point to next 8
         CPX #$0020      ; Done 256 Rages?
         BNE C35A26      ; Loop if not
         RTS

; Draw a row of two Rages
C35A49:  JSR C3D24D      ; Color: User's
         LDX #$0005      ; X: 5
         JSR .recur      ; Draw Rage A
         LDX #$0013      ; X: 19
.recur   JSR C35A64      ; Define source
         JSR C35A73      ; Draw Rage B
         INC $E5         ; Rage slot +1
         RTS

; Set source for loading enemy name
C35A64:  LDY.W #!nme_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!nme_np  ; CF/C800
         STY $EF         ; Set src LBs
         LDA.B #!nme_np!h; Bank: CF
         STA $F1         ; Set src HB
         RTS

; Draw Rage name
C35A73:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Rage in slot
;        CMP #$FF        ; None or Pugs?
         BEQ C35A95      ; Blank if so
         TXA             ; Rage slot
         JSR C38BF2      ; Load name
         JMP C387B_      ; Draw name

; Fork: Blank Rage slot
C35A95:  LDY.W #!nme_ns  ; Spaces: 8
         JMP spacedr     ; Draw 8 spaces

; Draw esper list and menu title, create portrait
C35AAC:  JSR C371A9      ; Clear BG1 map A
         JSR C3D24D      ; Color: User's
         JSR C35AC6      ; Draw esper list
         JSR C3D252      ; Color: Blue
         LDY #C36309     ; Text pointer
         JSR C30326      ; Draw "Espers"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Build and draw esper list
C35AC6:  JSR C35AE0      ; Build esper list
         JSR C38B78      ; Define $E5, $E6
         LDA #$09        ; Rows left: 9
C35ACF:  PHA             ; Save counter
         JSR C35B3D      ; Draw 2 espers
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35ACF      ; Loop till last
         RTS

; Build sorted esper list
C35AE0:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDX $00         ; Pack index: 0
         STZ $E0         ; Current: Ramuh
C35AEA:  LDY #$0008      ; Espers left: 8
         LDA $1A69,X     ; 8 owned espers
C35AF0:  ROR A           ; Got current?
         PHA             ; Save 8 espers
         BCC C35AFB      ; Blank if not
         LDA $E0         ; Esper number
         BRA C35AFD      ; Skip a line
C35AFB:  LDA #$FF        ; Esper: None
C35AFD:  STA $2180       ; Add to list
         INC $E0         ; Esper number +1
         PLA             ; 8 owned espers
         DEY             ; Espers left -1
         BNE C35AF0      ; Loop till last
         INX             ; Point to next 8
         CPX #$0004      ; Done 32 espers?
         BNE C35AEA      ; Loop if not

; Fork: Clear sorted list
C35B0C:  JSR wm9D89      ; WRAM: 7E/9D89
         LDA #$FF        ; Esper: None
         LDX #$001D      ; Slots left: 29
C35B17:  STA $2180       ; Clear list slot
         DEX             ; One less left
         BNE C35B17      ; Loop till last

; Fork: Build sorted list
C35B1D:  LDX #$9DED      ; 7E/9DED
         STX $2181       ; Set WRAM LBs
         LDY #$001B      ; Slots left: 27
         TDC             ; Clear A
C35B27:  LDA $2180       ; Esper in slot
         BMI C35B39      ; Skip if none
         PHA             ; Memorize it
         TAX             ; Index it
         LDA $D1F9B5,X   ; Intended slot
         DEC A           ; Subtract 1
         TAX             ; Index it
         PLA             ; Esper number
         STA $7E9D89,X   ; Add to new list
C35B39:  DEY             ; One less esper
         BNE C35B27      ; Loop till last
         RTS

; Draw a row of two esper names with MP cost
C35B3D:  LDX #$0003      ; X: 3
         JSR .recur      ; Draw esper A
         LDX #$0011      ; X: 17
.recur   JSR C35B54      ; Define source
         JSR C35B63      ; Draw esper B
         INC $E5         ; Esper slot +1
         RTS

; Set source for loading esper name
C35B54:  LDY.W #!esp_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!esp_np  ; ED/750E
         STY $EF         ; Set src LBs
         LDA.B #!esp_np!h; Bank: ED
         STA $F1         ; Set src HB
         RTS

; Draw esper's name and MP cost
C35B63:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Esper in slot
         BEQ C35BB6      ; Blank if none
         JSR C35BCD      ; Choose palette
         JSR C38BF2      ; Load name
         LDA.B #!2dot    ; Char: ".."
         STA $2180       ; Add to string
         JSR C357BB      ; Esper in slot
         CLC             ; Prepare ADC
         ADC #$36        ; Get attack ID
         JSR C357DC      ; Define MP cost
draw3n:  JSR C30563      ; Turn into text
         LDA $F7         ; Hundreds digit
         STA $2180       ; Add to string
         JMP draw2n_     ; Add tens, ones

; Fork: Blank esper slot
C35BB6:  LDY.W #!esp_ns+4; Spaces: 12
         JMP spacedr     ; Draw 12 spaces

; Define esper name color
C35BCD:  PHA             ; Save esper
         LDY #$001E      ; 1st: Guest 2
C35BD4:  REP #$20        ; 16-bit A
         TYX             ; Actor index
         LDA.L C370DB,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $1E,X       ; Actor's esper
         CMP $01,S       ; Matches ours?
         BEQ C35BEC      ; Gray out if so
         DEY             ; Actor index -1
         DEY             ; Actor index -1
         BPL C35BD4      ; Loop till < 0
         LDA #$20        ; Color: User's
         BRA C35BEE      ; Skip a line
C35BEC:  LDA #$28        ; Color: Gray
C35BEE:  STA $29         ; Set palette
         PLA             ; Esper to draw
         RTS

; Draw "<actor> has it!" in esper data menu
C35BF3:  JSR C3D24D      ; Color: User's
         LDY #$40DD      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDY #$0006      ; Letters: 6
C35C0B:  LDA $02,X       ; Name letter
         CMP #$FF        ; Terminator?
         BEQ C35C19      ; Done if so
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C35C0B      ; Loop till last
C35C19:  LDX $00         ; Letter: 1st
C35C1B:  LDA.L C3633B,X  ; Message letter
         BEQ C35C27      ; Done if end
         STA $2180       ; Add to string
         INX             ; Point to next
         BRA C35C1B      ; Do next letter
C35C27:  JMP C387B_      ; Draw message

; Draw Blitz inputs and menu title, create portrait
C35C2D:  JSR C371A9      ; Clear BG1 map A
         JSR C35C43      ; Draw inputs
         JSR C3D252      ; Color: Blue
         LDY #C36312     ; Text pointer
         JSR C30326      ; Draw "Blitz"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Build Blitz list and draw Blitz inputs
C35C43:  JSR C35C78      ; Build Blitz list
         JSR C38B78      ; Define $E5, $E6
         STZ $E5         ; Blitz slot: 1
         INC $E6         ; BG1 write row +1
         INC $E6         ; BG1 write row +1
         INC $E6         ; BG1 write row +1
         LDA #$04        ; Rows left: 4
C35C54:  PHA             ; Save counter
         JSR C35C67      ; Draw inputs x2
         JSR e6add4      ; BG1 WR row +4
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35C54      ; Loop till last
         RTS

; Draw a row of two sets of Blitz inputs
C35C67:  LDX #$0005      ; X: 5
         JSR C35CA0      ; Draw inputs A
         INC $E5         ; Blitz slot +1
         LDX #$0013      ; X: 19
         JSR C35CA0      ; Draw inputs B
         INC $E5         ; Blitz slot +1
         RTS

; Build SwdTech list
C359C9:  LDA $1CF7       ; Known SwdTechs
         BRA C35C80      ; Run Dance code

; Build Blitz list
C35C78:  LDA $1D28       ; Known Blitzes
         BRA C35C80      ; Run Dance code

; Build Dance list
C35C7D:  LDA $1D4C       ; Known Dances
C35C80:  JSR wm9D89      ; WRAM: 7E/9D89
         LDX $00         ; 1st: Wind Song
         LDY #$0008      ; Dances left: 8
C35C8B:  ROR A           ; Know current?
         PHA             ; Save 8 Dances
         BCC C35C95      ; Blank if not
         TXA             ; Dance number
         BRA C35C97      ; Skip a line
C35C95:  LDA #$FF        ; Dance: None
C35C97:  STA $2180       ; Add to list
         INX             ; Dance number +1
         PLA             ; Known Dances
         DEY             ; One less Dance
         BNE C35C8B      ; Loop till last
C35C9F:  RTS

; Draw Blitz's inputs
C35CA0:  JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Blitz in slot
         BEQ C35C9F      ; Abort if none

; Fork: Build tilemap for inputs
C35CE0:  XBA             ; Put Blitz in B
         LDA #$0C        ; Input data size
         JSR mul8        ; Blitz x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $7E9E89     ; Tilemap ptr
         STA $2181       ; Set WRAM LBs
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDY #$000A      ; Inputs: 10
C35CF6:  PHX             ; Save index
         LDA $C47A40,X   ; Blitz input
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C36274,X  ; Tile number
         STA $2180       ; Save in WRAM
         LDA.L C36274+1,X; Attributes
         STA $2180       ; Save in WRAM
         PLX             ; Input index
         INX             ; Input index +1
         DEY             ; One less input
         BNE C35CF6      ; Loop till last
         RTS

; Load esper description
C35D3C:  JSR C36261      ; Load pointers
         BRA C35D87      ; Load description

; Load Magic description
C35D42:  JSR C3623B      ; Load pointers
         BRA C35D87      ; Load description

; Load Lore description
C35D48:  LDX.W #!lor_dp  ; CF/FF3E
         STX $E7         ; Set ptr loc LBs
         LDX.W #!lor_dl  ; ED/FE00
         STX $EB         ; Set text loc LBs
         LDA.B #!lor_dp!h; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA.B #!lor_dl!h; Bank: ED
         STA $ED         ; Set text loc HB
         BRA C35D87      ; Load description

; Load SwdTech description
C35D5D:  LDX.W #!swt_d_p ; CF/FFAE
         STX $E7         ; Set ptr loc LBs
         LDX.W #!swt_d_l ; CF/FD00
         STX $EB         ; Set text loc LBs
         LDA.B #!swt_d_h ; Bank: CF
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         BRA C35D87      ; Load description

; Load Blitz description
C35D72:  LDX.W #!btz_d_p ; CF/FF9E
         STX $E7         ; Set ptr loc LBs
         LDX.W #!btz_d_l ; CF/FC00
         STX $EB         ; Set text loc LBs
         LDA.B #!btz_d_h ; Bank: CF
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB

; Load skill or item description
C35D87:  JSR wm9EC9      ; WRAM: 7E/9EC9
C35D8D:  JSR C3CF1D      ; Skill or item
C35D95:  CMP #$FF        ; Empty slot?
         BEQ C35DCA      ; Blank if so
C35D99:  REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAY             ; Index it
         LDA [$E7],Y     ; Relative ptr
         TAY             ; Index it
         SEP #$20        ; 8-bit A
C35DA2:  LDA [$EB],Y     ; Text character
         STA $2180       ; Add to string
         BEQ C35DAC      ; Branch if 00h
C35DA9:  INY             ; Index +1
         BRA C35DA2      ; Do next char

; Fork: Check if terminator
C35DAC:  DEY             ; Index -1
         LDA [$EB],Y     ; Previous char
         INY             ; Index +1
         CMP #$1C        ; Command 1C?
         BEQ C35DA9      ; Branch if so
         CMP #$1D        ; Command 1D?
         BEQ C35DA9      ; Branch if so
         CMP #$1E        ; Command 1E?
         BEQ C35DA9      ; Branch if so
         CMP #$1F        ; Command 1F?
         BEQ C35DA9      ; Branch if so
C35DC0:  RTS

; Fork: Empty slot (space is for item usage menu)
C35DCA:  STA $2180       ; Add a space
         STZ $2180       ; End string
         RTS

; Draw Dance list and menu title, create portrait
C35DD1:  JSR C371A9      ; Clear BG1 map A
         JSR C35DE7      ; Draw Dance list
         JSR C3D252      ; Color: Blue
         LDY #C36300     ; Text pointer
         JSR C30326      ; Draw "Dance"
         JSR C36802      ; Create portrait
         JMP C30FB8      ; Queue BG3 upload

; Build and draw Dance list
C35DE7:  JSR C35C7D      ; Build Dance list
         JSR C3D24D      ; Color: User's
         JSR C38B78      ; Define $E5, $E6
         INC $E6         ; BG1 write row +1
         INC $E6         ; BG1 write row +1
         STZ $E5         ; Dance slot: 1
         LDA #$04        ; Rows left: 4
C35DF6:  PHA             ; Save counter
         JSR C35E09      ; Draw 2 dances
         JSR e6add4      ; BG1 WR row +4
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C35DF6      ; Loop till last
         RTS

; Draw a row of two Dance names
C35E09:  LDX #$0005      ; X: 5
         JSR .recur      ; Draw Dance A
         LDX #$0013      ; X: 19
.recur   JSR C35E20      ; Define source
         JSR C35E2F      ; Draw Dance B
         INC $E5         ; Dance slot +1
         RTS

; Set source for loading Dance name
C35E20:  LDY.W #!dnc_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!dnc_np  ; ED/7C51
         STY $EF         ; Set src LBs
         LDA.B #!dnc_np!h; Bank: ED
         STA $F1         ; Set src HB
C35E2E:  RTS

; Draw Dance name
C35E2F:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Dance in slot
         BEQ C35E2E      ; Abort if none
         JSR C38BF2      ; Load name
         JMP C387B_      ; Draw name

; Set to delete portrait in Skills or Status menu
C35E66:  TDC             ; Clear A
         LDA $60         ; Queue index
         TAX             ; Index it
         LDA #$FF        ; Null value
         STA $7E35C9,X   ; Portrait: Off
         RTS

; Draw and upload spell usage menu
C35E71:  JSR C371BC      ; Clear BG2 map A
         LDX #C35E9E     ; C3/5E9E
         JSR boxes_      ; Upload windows
         JSR C371AD      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C33225      ; Draw party info
         JSR C35EAA      ; Draw spell, cost
         JMP up_txt      ; Upload text maps

; Draw spell name and cost message for spell usage menu
C35EAA:  JSR C3D24D      ; Color: User's
         LDY #C35EE2     ; Text pointer
         JSR C30326      ; Draw "MP Needed"
         LDA $4B         ; Cursor slot
         STA $E5         ; Set spell slot
         JSR C35692      ; Define source
         LDY #$78CF      ; Tilemap ptr
         JSR C335E1      ; Set position
         JSR C357BB      ; Spell
         JSR C38BF2      ; Load spell name
         JSR C387B_      ; Draw spell name
         JSR C357BB      ; Spell
         JSR C357DC      ; Define MP cost
         JSR C30563      ; Turn into text
         LDX #$7A53      ; Text position
         JMP C30539      ; Draw 2 digits

; Initialize esper data menu
C35EEC:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         JSR C361AC      ; Load esper info
         JSR C35FF4      ; Draw esper info
         JSR C30F7C      ; Queue its upload
         JSR C313D3      ; Upload it now
         JSR C30F68      ; Requeue esper list
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9A10     ; Hide esper list
         SEP #$20        ; 8-bit A
         LDA $49         ; Top BG1 write row
         STA $5F         ; Save for return
         LDA #$07        ; BG1 VRAM row: 7
         STA $49         ; Save for V-Shift
         JSR C354F3      ; Load V-shift data
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDY #C35FE1     ; C3/5FE1
         JSR C30681      ; Load navig dat
         JMP C35FDB      ; Relocate cursor

; 4D: Sustain esper data menu
C35F23:  JSR C35FD8      ; Handle D-Pad
         JSR C361EB      ; Load description
         LDA $08         ; Pushing A?
         BPL C35F5F      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; On esper name?
         BNE C35F5F      ; Branch if not
         LDA $99         ; Viewed esper
         JSR C35BCD      ; Choose palette
         STA $E0         ; Memorize esper
         LDA $29         ; Esper palette
         CMP #$28        ; Grayed out?
         BNE C35F57      ; Equip if not
         JSR C30F2B      ; Play buzzer
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C35BF3      ; Draw who has it
         LDY #$0020      ; Frames: 32
         STY $20         ; Set exit delay
         LDA #$34        ; C3/29AD
         STA $26         ; Next: Late exit
         JMP C30F7C      ; Queue text upload

; Fork: Equip esper
C35F57:  JSR C30F1D      ; Sound: Click
         JSR C3299C      ; Equip/draw esper
         BRA C35F68      ; Exit submenu

; Fork: Handle B
C35F5F:  LDA $09         ; Pushing B?
         BPL C35FD1      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C35F68:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         LDA $5F         ; Top BG1 write row
         STA $49         ; Restore it
         JSR C35AC6      ; Draw esper list
         JSR C3211_      ; Create bar, etc.
         JSR oldcur      ; Restore cursor pos
         JSR C352D6      ; Relocate cursor
         JSR C30F68      ; Queue list upload
         JSR C313D3      ; Refresh esper list
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide esper list
         SEP #$20        ; 8-bit A
         JSR C354F3      ; Load V-shift data
         JMP C30F7C      ; Queue stats upload
C35FD1:  RTS

; Handle D-Pad for esper data menu
C35FD8:  JSR C307B0      ; Handle D-Pad
C35FDB:  LDY #C35FE6     ; C3/5FE6
         JMP C306C3      ; Relocate cursor

; Draw selected esper's info
C35FF4:  JSR C3D24D      ; Color: User's
         LDY #C3634C     ; Text pointer
         JSR C30326      ; Do "Learn.Rate"
         LDY #C36343     ; Text pointer
         JSR C30326      ; Draw "Skill"
         LDA $99         ; Viewed esper
         JSR C35BCD      ; Choose palette
         LDY #$4451      ; Tilemap ptr
         JSR C335E1      ; Set pos, WRAM
         LDA $99         ; Viewed esper
         JSR drw_esp     ; Draw its name

; Fork: Draw spell data
C3602A:  JSR C3D24D      ; Color: User's
         LDA $99         ; Viewed esper
         XBA             ; Put in B
         LDA #$0B        ; Esper data size
         JSR mul8        ; Esper x size
         TAX             ; Index product
         LDY #$0012      ; Y: 18
C36049:  STY $F5         ; Memorize it
         REP #$20        ; 16-bit A
         LDA $E6F567,X   ; Spell and rate
         STA $E0         ; Memorize them
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         PHX             ; Save index
         LDX #$0005      ; X: 5
;        LDY $F5         ; Y position
         LDA $E1         ; Spell
         PHA             ; Preserve it
         JSR C36136      ; Draw spell, rate
         LDX #$0018      ; X: 24
         LDY $F5         ; Y position
         PLA             ; Spell
         STA $E1         ; Restore it
         JSR C360D9      ; Draw percentage
         PLX             ; Spell data index
         LDY $F5         ; Y position
         INY             ; Y position +1
         INY             ; Y position +1
         CPY #$001C      ; Done 5 spells?
         BNE C36049      ; Loop if not

; Fork: Draw esper bonus message
C3607E:  LDY #$4753      ; Tilemap ptr
         JSR C335E1      ; Set pos, WRAM
         LDA $E6F567,X   ; Esper bonus
         CMP #$FF        ; None?
         BEQ C360BC      ; Blank if so
         XBA             ; Put in B
         LDA.B #!esb_ns  ; Text length
         JSR mul8        ; Bonus x length
         LDX $00         ; Char index: 0
C36098:  LDA.L C36357,X  ; "At..." char
         BEQ .skip       ; If terminator
         STA $2180       ; Add to string
         INX             ; Point to next
         BRA C36098      ; Load next char
.skip    LDX $4216       ; Index product
         LDY.W #!esb_ns  ; Letters: 8
C360AB:  LDA.L !esb_np,X ; Bonus char
         STA $2180       ; Add to string
         INX             ; Point to next
         DEY             ; One less left
         BNE C360AB      ; Loop till last
         JMP C387B_      ; Draw string

; Fork: Blank esper bonus message
C360BC:  LDY #$0019      ; Spaces: 25
         JMP spacedr     ; Draw 25 spaces

; Draw spell's mastery percentage for esper data menu
C360D9:  JSR C36195      ; Define position
         JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C36126      ; Blank if so
         JSR C35771      ; Spell mastery
         CMP #$FF        ; Fully learned?
         BEQ C36117      ; Branch if so
         JSR C30563      ; Turn into text
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         JSR add2n       ; Add mastery
C3610C:  LDA.B #!perc    ; Char: "%"
         STA $2180       ; Add to string
C36111:  JMP C387B_      ; Draw string

; Fork: Draw "100%"
C36117:  LDA.B #!num1    ; Char: "1"
         STA $2180       ; Add to string
         LDA.B #!num0    ; Char: "0"
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         BRA C3610C      ; Add "%"; draw

; Fork: Blank percentage
C36126:  LDY #$0004      ; Spaces: 4
         JSR spaces      ; Add to string
         BRA C36111      ; Draw 4 spaces

; Draw spell's name and learning rate
C36136:  JSR C36195      ; Define position
C36142:  JSR C35692      ; Define source
         LDA $E1         ; Spell
         CMP #$FF        ; None?
         BEQ C3617E      ; Blank if so
         JSR C38BF2      ; Load name
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
         LDA #$FF        ; Space char
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         STA $2180       ; Add to string
         LDA.B #!mult    ; Char: "×"
         STA $2180       ; Add to string
         LDA $E0         ; Learning rate
         JMP draw2n      ; Draw string

; Fork: No spell
C3617E:  LDY #$000F      ; Spaces: 15
         JMP spacedr     ; Draw 15 spaces

; Compute position into BG1 tilemap B
C36195:  REP #$20        ; 16-bit A
         TYA             ; Y position
         JSR x64         ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         ADC $E7         ; Add Y x64
         ADC #$4049      ; Add base adr
         STA $7E9E89     ; Set position
         SEP #$20        ; 8-bit A
         RTS

; Load esper's info for display
C361AC:  LDX #$AB8D      ; 7E/AB8D
         STX $2181       ; Set WRAM LBs
         LDA $99         ; Chosen esper
         STA $2180       ; Add to list
         XBA             ; Put in B
         LDA #$0B        ; Esper data size
         JSR mul8        ; Esper x size
         TAX             ; Index product
         LDY #$0005      ; Spells left: 5
C361D3:  INX             ; Skip Learn.Rate
         LDA $E6F567,X   ; Spell taught
         STA $2180       ; Add to list
         INX             ; ROM index +1
         DEY             ; One less spell
         BNE C361D3      ; Loop till last
         LDA $E6F567,X   ; Level up bonus
         STA $2180       ; Add to list
         RTS

; Load description for esper data menu
C361EB:  JSR wm9EC9      ; WRAM: 7E/9EC9
         TDC             ; Clear A
         LDA $4B         ; Cursor row
         TAX             ; Index it
         LDA $7EAB8D,X   ; Slot content
         CMP #$FF        ; Empty slot?
         BEQ C36229      ; Blank if so
         PHA             ; Memorize it
         JSR C36233      ; Load pointers
         PLA             ; Slot content
         JMP C35D99      ; Load desc

; Fork: Empty slot
C36229:  STZ $2180       ; End string
         RTS

; Load description pointers for esper data menu
C36233:  LDA $4B         ; On esper name?
         BEQ C36261      ; Branch if so
         CMP #$06        ; On bonus?
         BEQ C3624E      ; Branch if so

; Fork: Magic effect
C3623B:  LDX.W #!mag_dp  ; E6/F690
         STX $E7         ; Set ptr loc LBs
         LDX.W #!mag_dl  ; D8/C9A0
         STX $EB         ; Set text loc LBs
         LDA.B #!mag_dp!h; Bank: E6
         STA $E9         ; Set ptr loc HB
         LDA.B #!mag_dl!h; Bank: D8
         STA $ED         ; Set text loc HB
         RTS

; Fork: Level up bonus
C3624E:  LDX.W #!esb_dp  ; CF/FFD0
         STX $E7         ; Set ptr loc LBs
         LDX.W #!esb_dl  ; D0/F600
         STX $EB         ; Set text loc LBs
         LDA.B #!esb_dp!h; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA.B #!esb_dl!h; Bank: D0
         STA $ED         ; Set text loc HB
         RTS

; Fork: Esper effect
C36261:  LDX.W #!esp_dp  ; CF/FE40
         STX $E7         ; Set ptr loc LBs
         LDX.W #!esp_dl  ; D8/CDA0
         STX $EB         ; Set text loc LBs
         LDA.B #!esp_dp!h; Bank: CF
         STA $E9         ; Set ptr loc HB
         LDA.B #!esp_dl!h; Bank: D8
         STA $ED         ; Set text loc HB
         RTS

; Tile attributes for Blitz inputs
C36274:  dw $0000        ; Terminator
         dw $0000        ; Bogus; for A
         dw $0000        ; Bogus; for B
         dw $2037        ; X
         dw $2038        ; Y
         dw $202B        ; L
         dw $2031        ; R
         dw $20D6        ; Down-left
         dw $A0D4        ; Down
         dw $60D6        ; Down-right
         dw $20D5        ; Right
         dw $C0D6        ; Up-right
         dw $20D4        ; Up
         dw $A0D6        ; Up-left
         dw $60D5        ; Left

; Draw and upload Status menu, create portrait
C36362:  JSR C36374      ; Draw main windows
         JSR C3641E      ; Draw Gogo's panel
         JSR C36399      ; Draw blue text
         JSR C365E3      ; Draw actor info
         JSR C363D4      ; Upload tilemaps
         JMP C36802      ; Create portrait

; Draw windows for non-shifted Status menu
C36374:  JSR C371A9      ; Clear BG1 map A
         JSR C371B7      ; Clear BG1 map D
         JSR bg3d_cl     ; Clear BG3 maps
         LDX #C365CF     ; C3/65CF
         JMP boxes       ; Draw windows

; Draw blue text and non-blue symbols in Status menu
C36399:  JSR C3639E      ; LV, HP, MP, %, /
         JSR C3D252      ; Color: Blue
         LDX #C36A80     ; Text ptrs loc
         LDA #$0C        ; Strings: 12
         JSR C3712C      ; Draw Vigor, etc.
         LDX #C36AA6     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JMP C3714E      ; Draw Speed, etc.

; Draw LV, HP, MP, and non-blue symbols in Status menu
C3639E:  JSR C3D24D      ; Color: User's
         LDX #C36A9E     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C3712C      ; Draw 2x / and %
         JSR C3658A      ; Color: Blue
         LDX #C36A98     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JMP C3712C      ; Draw "LV/HP/MP"

; Upload common tilemaps (non-scrollable list)
C363D4:  JSR C30EBD      ; Upload BG2 A+B
up_txt:  JSR C30E93      ; Upload BG1 A+B
up_bg3:  JSR C30ED9      ; Upload BG3 A+B
         JMP C30EE7      ; Upload BG3 C+D

; Handle member switching in Status menu
C363E0:  JSR C3639E      ; Draw "MP" + "/"
         JSR C365E3      ; Draw actor info
         JSR C367F8      ; Create portrait
         JSR C30F68      ; Queue BG1a upload
         JSR C30FCC      ; Queue BG3a upload
         JSR C3121B      ; Swap portraits
         JSR C313D3      ; Trigger NMI
         JSR C30FF4      ; Dequeue BG3a
         LDY #$4800      ; $4800 = BG3c
         STY $14         ; Set VRAM ptr
         LDY #$8849      ; 7E/8849
         STY $16         ; Set src LBs
         JMP C313D3      ; Upload BG3c

; Draw Gogo's list of available commands, prepare portrait hiding
C3641E:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A

; Fork: Compile everyone's commands, exclude guests and dead Shadow
C36425:  TAX             ; 1st: Terra
C36426:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDY #$0004      ; Commands: 4
         LDA $1EDC       ; Eligible actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C36458      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
.loop1   LDA $16,X       ; Command
         STA $2180       ; Add to list
         INX             ; Point to next
         DEY             ; One less left
         BNE .loop1      ; Loop till 4th
         BRA C36468      ; Do next actor
C36458:  SEP #$20        ; 8-bit A
         LDA #$FF        ; Command: None
.loop2   STA $2180       ; Add to list
         DEY             ; One less left
         BNE .loop2      ; Loop till 4th
C36468:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done 16 actors?
         BNE C36426      ; Loop if not

; Fork: Delete duplicates
C3646F:  TDC             ; Clear A
         TAX             ; Cmd slot: 1
C36471:  PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
C36476:  CMP $7E9E0A,X   ; Duplicate?
         BNE C36484      ; Branch if not
         PHA             ; Save command
         LDA #$FF        ; Command: None
         STA $7E9E0A,X   ; Clear duplicate
         PLA             ; Battle command
C36484:  INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C36476      ; Loop if not
         PLX             ; Base cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C36471      ; Loop if not

; Fork: Build final command list
C36491:  JSR wm9D8A      ; WRAM: 7E/9D8A
         LDA #$FF        ; Cmd: Empty
         STA $2180       ; Add to list
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         TAY             ; Cmd count: 0
C3649F:  TDC             ; ...
         PHX             ; Save cmd slot
         LDA $7E9E09,X   ; Available cmd
         BMI C364BD      ; Skip if none
         CMP #$12        ; Mimic?
         BEQ C364BD      ; Skip if so
         STA $E0         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFFE00,X   ; Properties
         LSR A           ; Gogo can use?
         BCC C364BD      ; Skip if not
         LDA $E0         ; Command
         STA $2180       ; Add to list
         INY             ; Cmd count +1
C364BD:  PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX #$0040      ; Done 16 x 4?
         BNE C3649F      ; Loop if not
         INY             ; Cmd count +1
         TYA             ; Put it in A
         STA $7E9D89     ; Set list size

; Fork: Load window layout for command list
C364CA:  LDX #$0007      ; Base index
C364D2:  LDA.L C365DB,X  ; Window data
         STA $7EAA8D,X   ; Save in RAM
         DEX             ; Index -1
         BPL C364D2      ; Loop till < 0

; Fork: Draw both segments of command window
C364DF:  TYA             ; Command count
         STA $E2         ; Memorize it
         ASL A           ; x2
         ADC $E2         ; x3
         AND #$FE        ; -1 if odd
         BEQ C364ED      ; Branch if no cmd
         INC A           ; +1
         INC A           ; +1
C364ED:  LSR A           ; ÷2
         STA $7EAA90     ; Set L-Win heigth
         STA $7EAA94     ; Set R-Win heigth
         LDX #$AA8D      ; 7E/AA8D
         LDA #$7E        ; Bank: 7E
         JSR C303C6      ; Draw left box
         LDX #$AA91      ; 7E/AA91
;        LDA #$7E        ; ...
;        STA $E9         ; ...
         JSR C303C8      ; Draw right box

; Fork: Draw command list, prepare portrait hiding
C3650A:  LDA $7E9D89     ; List size
         STA $E5         ; Memorize it
         STZ $E6         ; Clear HB
         TDC             ; Clear A
         TAX             ; Cmd slot: 1
         LDY #$808B      ; Tilemap ptr
C36517:  PHX             ; Save cmd slot
         PHY             ; Save position
         LDA $7E9D8A,X   ; Available cmd
         JSR C36534      ; Draw cmd name
         PLY             ; Text position
         REP #$21        ; 16-bit A; C-
         TYA             ; Put in A
         ADC #$0080      ; +2 rows down
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         PLX             ; Cmd slot
         INX             ; Cmd slot +1
         CPX $E5         ; End of list?
         BNE C36517      ; Loop if not

; Fork: Set a section of menu to mask wrapping Gogo portrait
C365A6:  LDX #$61CA      ; Tilemap ptr
         STX $E7         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set dst HB
         LDX #$0006      ; Rows left: 6
C365B2:  LDY $00         ; Map index: 0
         LDA #$3D        ; Pal 7, priority
C365B6:  STA [$E7],Y     ; Set attributes
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0012      ; Done 9 tiles?
         BNE C365B6      ; Loop if not
         REP #$21        ; 16-bit A; C-
         LDA $E7         ; Tilemap ptr
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         SEP #$20        ; 8-bit A
         DEX             ; One less row
         BNE C365B2      ; Loop till last
         RTS

; Draw battle command name, ignore modifiers
C36534:  PHA             ; Save command
         JSR C335E1      ; Set pos, WRAM
         PLA             ; Battle command
         BPL C36543      ; Draw it if any
C36565:  LDY.W #!cmd_ns  ; Spaces: 6
         JMP spacedr     ; Draw 6 spaces

; Draw battle command name, apply modifiers
C3653E:  JSR C36782      ; Apply modifiers
         BMI C36565      ; Blank if no cmd
C36543:  PHA             ; Save command
         JSR C3657B      ; Pick a palette
         PLA             ; Command
         XBA             ; Put in B
         LDX.W #!cmd_ns  ; Letters: 6
         LDA.B #!cmd_np!h; Text ptr HB
         LDY.W #!cmd_np  ; Text ptr LBs
         JSR fw_txt      ; Load name
C3655F:  JMP C387B_      ; Draw cmd name

; Select a palette for battle command
C3657B:  CMP #$0B        ; Runic?
         BEQ C36590      ; Branch if so
         CMP #$07        ; SwdTech?
         BEQ C3659A      ; Branch if so
C36584:  JMP C3D24D      ; Color: User's

; Fork: Handle Runic
C36590:  LDA $11DA       ; R-Hand can Runic?
         ORA $11DB       ; Or L-Hand?
         BPL C3658A      ; Gray out if not
         BRA C36584      ; Use user's color

; Fork: Handle SwdTech
C3659A:  LDA $11DA       ; R-Hand flags
         ORA $11DB       ; Add L-Hand's
         BIT #$02        ; Can use SwdTech?
         BNE C36584      ; User color if so

; Fork: Set to gray
C3658A:  LDA #$24        ; Palette 1
         STA $29         ; Color: Gray
         RTS

; Draw actor info in Status menu
C365E3:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         ASL A           ; Double it
         TAY             ; Index it
         LDA $69,X       ; Actor
         LDX $6D,Y       ; Actor address
         STX $67         ; Memorize it
C36618:  JSL $C20006     ; Load properties
         LDY $67         ; Actor's address
         JSR C3A1D7      ; Set Bat.Pwr mode
         JSR C3D24D      ; Color: User's
         PEA $8861       ; Pos for Mag.Pwr
         PEA $7FE1       ; Pos for Stamina
         PEA $7F61       ; Pos for Speed
         PEA $7EE1       ; Pos for Vigor
         PEA $7F7D       ; Pos for Evade
         PEA $887D       ; Pos for MBlock
         LDX #$000A      ; 1st: MBlock
.loop    STX $FE         ; Save stat index
         LDA $11A0,X     ; Stat value
         JSR C30563      ; Turn into text
         PLX             ; Text position
         JSR C30543      ; Draw 3 digits
         LDX $FE         ; Stat index
         DEX             ; Stat index -1
         DEX             ; Stat index -1
         BPL .loop       ; Loop till < 0
         JSR C39B5A      ; Define Bat.Pwr
         JSR C305B1      ; Turn into text
         LDX #$7E7D      ; Text position
         JSR C30509      ; Draw 3 digits
         LDA $11BA       ; Defense
         JSR C30563      ; Turn into text
         LDX #$7EFD      ; Text position
         JSR C30543      ; Draw 3 digits
         LDA $11BB       ; Mag.Def
         JSR C30563      ; Turn into text
         LDX #$7FFD      ; Text position
         JSR C30543      ; Draw 3 digits
         LDY #$394F      ; Text position
         JSR C3356A      ; Draw actor name
         LDY #$395D      ; Text position
         JSR C33580      ; Draw actor class
         LDY #$3971      ; Text position
         JSR C335AE      ; Draw held esper
         JSR C36758      ; Draw commands
         JSR C3D24D      ; Color: User's
         LDX #C366EC     ; Coords tbl ptr
         JSR C30CD7      ; Draw LV, HP, MP
         LDX $67         ; Actor's address
         LDY $11,X       ; Experience LBs
         STY $F1         ; Memorize them
         LDA $13,X       ; Experience HB
         STA $F3         ; Memorize it
         JSR C30605      ; Turn into text
         LDX #$7CD7      ; Text position
         JSR C30526      ; Draw 8 digits
         JSR C366F6      ; Get needed exp
         JSR C30605      ; Turn into text
         LDX #$7DD7      ; Text position
         JSR C30526      ; Draw 8 digits
         STZ $47         ; Ailments: Off
         JSR C3121B      ; Hide ail. icons
         JMP C368A4      ; Display status

; Calculate experience needed to level up
C366F6:  TDC             ; Clear A
         TAX             ; Clear X
         STX $F1         ; Needed XP LBs
         STX $F3         ; Needed XP HB
         LDX $67         ; Actor's address
         LDA $08,X       ; Level
         CMP #$63        ; 99?
         BEQ C36757      ; Zero if so
         JSR C36720      ; Get needed XP
         LDX $67         ; Actor's address
         LDA $F1         ; Needed XP LBs
         SEC             ; Prepare SBC
         SBC $11,X       ; Deduct XP LBs
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         LDA $F3         ; Needed XP HB
         SBC $13,X       ; Deduct XP HB
         STA $F3         ; Save changes
         RTS

; Calculate total experience needed to level up
C36720:  TAY             ; Levels left
         LDX $00         ; 1st: Level 1
C3672B:  REP #$21        ; 16-bit A; C-
         LDA $ED8220,X   ; Needed XP
         ADC $F1         ; Add total LBs
         STA $F1         ; Set total LBs
         BCC .next       ; If no overflow
         INC $F3         ; Total HB +1
.next    INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less level
         BNE C3672B      ; Loop till last

; Fork: Octuple total to get true value
C36747:  LDX #$0003      ; Loop counter
.loop    ASL $F1         ; Total LBs x2
         ROL $F3         ; HBs x2 + C
         DEX             ; Counter -1
         BNE .loop       ; Loop till 0
C36757:  RTS

; Draw actor's command list in Status menu
C36758:  PEA $7BB1       ; Cmd1 position
         PEA $7C31       ; Cmd2 position
         PEA $7CB1       ; Cmd3 position
         LDY #$7D31      ; Cmd4 position
         JMP cmdx4       ; Draw cmd names

; Handle battle command modifiers
C36782:  LDA $0016,Y     ; Command
         CMP #$02        ; Magic?
         BNE C36793      ; Branch if not
         PHY             ; Save index
         JSR C30D96      ; Can use magic?
         PLY             ; Actor's address
         BCS C367C5      ; Branch if so
         BRA C367B_      ; Command: None

; Fork: Morph
C36793:  CMP #$03        ; Morph command?
         BNE C367A5      ; Branch if not
         LDA $1DD1       ; Event flags
         BIT #$04        ; Unlocked Morph?
         BNE C367C5      ; Branch if so
         BRA C367B_      ; Command: None

; Fork: Leap
C367A5:  CMP #$11        ; Leap command?
         BNE C367B6      ; Branch if not
         LDA $11E4       ; Veldt flags
         BIT #$04        ; Can show Leap?
         BNE C367C5      ; Branch if so
         BRA C367B_      ; Command: None

; Fork: Dance
C367B6:  CMP #$13        ; Dance command?
         BNE C367C5      ; Branch if not
         LDA $1D4C       ; Known Dances
         BNE C367C5      ; Branch if any
C367B_:  LDA #$FF        ; Command: None
         RTS

; Fork: Relic effects
C367C5:  LDA $0016,Y     ; Command
         STA $E0         ; Memorize it
         TDC             ; Clear A
         TAX             ; 1st: Capture
         LDA $11D6       ; Relic effects
         AND #$7C        ; Cmd upgrades
         ASL A           ; Shift bits
C367D2:  ASL A           ; Got current?
         BCC C367DF      ; Skip if not
         PHA             ; Save upgrades
         LDA.L C367EE,X  ; Cmd to switch
         CMP $E0         ; Current cmd?
         BEQ C367E8      ; Replace if so
         PLA             ; Cmd upgrades
C367DF:  INX             ; Index +1
         CPX #$0005      ; Done Fight?
         BNE C367D2      ; Loop if not
         LDA $E0         ; Original cmd
         RTS

; Fork: Replace command
C367E8:  PLA             ; Clean stack
         LDA.L C367F3,X  ; New command
         RTS

; Commands to upgrade
C367EE:  db $05          ; Steal
         db $0F          ; Slot
         db $0D          ; Sketch
         db $02          ; Magic
         db $00          ; Fight

; Command upgrades
C367F3:  db $06          ; Capture
         db $18          ; GP Rain
         db $0E          ; Control
         db $17          ; X Magic
         db $16          ; Jump

; Replace portrait in Status menu after actor swap
C367F8:  JSR C35E66      ; Hide old one

; Create portrait by upper-left corner
C36802:  JSR C36823      ; Queue OAM fn
         BRA C3682F      ; Init sprite

; Create portrait for Equip or Relic menu
C36808:  JSR C36823      ; Queue OAM fn
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         LDA #$C8        ; X: 200
         STA $33CA,X     ; Set sprite's
;        TDC             ; Clear A
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C36844      ; Set Y, ptr
         PLB             ; Restore DB
         RTS

; Create portrait A
C36823:  LDY #C30B7D     ; C3/0B7D
         JSR qanim3      ; Queue OAM fn
         TXA             ; Queue index
         STA $60         ; Set sprite's
         RTS

; Place portrait by upper-left corner, set pose timer
C3682F:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         TDC             ; Clear A
         LDA $28         ; Member slot
         TAY             ; Put in Y
         JSR C30B5C      ; Set X position
         JSR C36844      ; Set Y, ptr
         PLB             ; Restore DB
         RTS

; Initialize variables for portrait by either upper corner
C36844:  LDA #$30        ; Y: 48
         STA $344A,X     ; Set sprite's
         JMP C30B37      ; Load anim ptr

; Set to condense BG3 text in Status menu
C36854:  LDY #C36873     ; C3/6873
         JMP bg3v_       ; Queue BG3 V-Pan

; Display status effects in Status menu
C368A4:  LDY #$38DD      ; Text position
         LDX #$1050      ; Icon position
         STX $E7         ; Set as current
         JSR C335E1      ; Set text pos
         LDA $0014,Y     ; Wounded?
         BMI C36930      ; Draw it if so
         AND #$70        ; Clear/Imp/Pet
         STA $E1         ; Memorize them
         LDA $0014,Y     ; Status effects
         AND #$07        ; Dark/Zom/Poison
         ASL A           ; Put in b1-b3
         STA $E2         ; Memorize them
         LDA $0015,Y     ; Status effects
         AND #$80        ; Isolate Float
         ORA $E1         ; Add Clear, etc.
         ORA $E2         ; Add Dark, etc.
         BEQ C3692A      ; Blank if none
         STZ $48         ; Icon fn mode: 0
         JSR icons       ; Create icons
C3692A:  LDY #$0008      ; Spaces: 8
         JSR spaces      ; Add to string
         JMP C387B_      ; Blank "Wounded"

; Fork: Draw "Wounded"
C36930:  LDX $00         ; Index: 0
C36938:  LDA.L C337E3,X  ; Letter
         STA $2180       ; Add to string
         INX             ; Point to next
         CPX #$0008      ; Copied 8?
         BNE C36938      ; Loop if not
         JSR C3880B      ; Color: Gray
         JMP C387B_      ; Draw string

; 42: Initialize Lineup's Status menu
C36966:  JSR C335F7      ; Reset/Stop stuff
         LDA $0200       ; Menu number
         STA $22         ; Memorize it
;        STZ $0200       ; Actor arrows: Off...
;        STZ $25         ; Never read...
         LDA #$80        ; Channel: 7
         TRB $43         ; Halt HDMA-7
         JSR C36854      ; Set to shift text
         JSR C3699D      ; Draw menu; portrait
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$43        ; C3/6988
         STA $27         ; Queue: Sustain menu
         JMP C33609      ; BRT:1 + NMI

; 43: Sustain Lineup's Status menu
C36988:  LDA $09         ; Pushing B?
         BPL C369C1      ; Exit if not
         LDA #$7D        ; C3/78C5
         STA $27         ; Queue menu exit
         STZ $26         ; Next: Fade-out
         LDA $22         ; Former menu
         STA $0200       ; Set as current
         JMP C30F14      ; Sound: Cursor

; Draw Lineup's Status menu, create portrait
C3699D:  JSR C36374      ; Draw windows
         JSR C36399      ; Draw blue text
         JSR C369C2      ; Get actor address
         JSR C36618      ; Draw actor info
         JSR C363D4      ; Upload tilemaps
         JSR C36823      ; Init portrait
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         TDC             ; Clear A
         LDA $28         ; Actor
         TAY             ; Index it
         JSR C369D7      ; Set portrait's X
         TDC             ; Clear A
         TAY             ; Portrait slot: 1
         JSR C36844      ; Set Y, ptr
         PLB             ; Restore DB
C369C1:  RTS

; Load actor number and address for Lineup's Status menu
C369C2:  TDC             ; Clear A
         LDA $C9         ; Actor
         STA $28         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         TDC             ; ...
         LDA $C9         ; Actor
         RTS

; Set portrait's X position for Lineup's Status menu
C369D7:  LDA $1850,Y     ; Actor info
         BIT #$20        ; Back row?
         BEQ C369E5      ; Branch if not
         LDA #$1A        ; X: 26
         BRA C369EA      ; Skip a line
C369E5:  LDA #$0E        ; X: 15
C369EA:  STA $33CA,X     ; Set sprite's
C369EF:  RTS

; 6A: Sustain shifted Status menu
C369F0:  JSR C36A52      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C36A23      ; Branch if not
         JSR C30F1D      ; Sound: Click
         STZ $65         ; Edited slot HB
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Chosen command
         PHA             ; Memorize it
         JSR C32D9E      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         ADC $64         ; Add edited slot
         TAY             ; Index sum
         SEP #$20        ; 8-bit A
         PLA             ; Chosen command
         STA $0016,Y     ; Assign to actor
         JSR C36758      ; Redraw commands
         BRA C36A2C      ; Shift screen

; Fork: Handle B
C36A23:  LDA $09         ; Pushing B?
         BPL C369EF      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C36A2C:  LDA #$01        ; Blinker: Off
         TRB $46         ; Set menu flag
         LDA #$06        ; Frames: 6
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$0C        ; C3/2255
         STA $27         ; Queue: Normal menu
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Shift screen
         JSR C337C7      ; Load navig data
         LDA $64         ; Old cursor row
         STA $4E         ; Set as current
         JMP C337D0      ; Relocate cursor

; Handle D-Pad for shifted Status menu
C36A52:  JSR C307B0      ; Handle D-Pad
C36A55:  LDY #C36A60     ; C3/6A60
         JMP C306C3      ; Relocate cursor

; 5D: Initialize actor naming menu
C36B5E:  JSR C335F7      ; Reset/Stop stuff
         LDY $0201       ; Actor's address
         STY $67         ; Memorize it
         JSR C37076      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Page: 1st
         LDY #C36D2F     ; C3/6D2F
         JSR C30681      ; Load navig data
         JSR C36D29      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C36E29      ; Draw menu
         JSR C36D09      ; Set arrow's column
         LDY #C36FCA     ; C3/6FCA
         JSR qanim1      ; Queue large arrow
         JSR C36F63      ; Set to shift text
         JSR C36EB3      ; Get portrait colors
         JSR C36E98      ; Upload portrait GFX
         JSR C36DFC      ; Create portrait
         LDY #C3702C     ; C3/702C
         JSR qanim2      ; Queue small arrow
         LDA #$5F        ; C3/6BA5
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 5F: Sustain actor naming menu
C36BA5:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C36BB9      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$09        ; On bottom row?
         BNE C36BB9      ; Branch if not
         LDA #$60        ; C3/6C4A
         STA $26         ; Next: Scroll
         LDA #$15        ; Frames: 21
         STA $20         ; Set scroll timer

; Fork: Handle upward scrolling
C36BB9:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C36BCB      ; Branch if not
         LDA $4E         ; On top row?
         BNE C36BCB      ; Skip if not
         LDA #$61        ; C3/6C71
         STA $26         ; Next: Scroll
         LDA #$15        ; Frames: 21
         STA $20         ; Set scroll timer

; Fork: Handle L and R and intrapage navigation, redraw name
C36BCB:  JSR C30F54      ; Queue text upload
         JSR C36C99      ; Handle L and R
         JSR C36D26      ; Handle D-Pad
         JSR C36E86      ; Draw actor name

; Fork: Handle Start
C36BD7:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BEQ C36BE0      ; Branch if not
         LDY $67         ; Actor's address
         LDA $0002,Y     ; First letter
         INC A           ; Terminator?
         BNE C36C3D      ; Valid if not
         JMP C3C5C6      ; Buzzer + Mosaic
C36C3D:  JSR C30F1D      ; Sound: Click
;        STZ $0205       ; Never read...
         JMP fdexit      ; Queue menu exit

; Fork: Handle A
C36BE0:  LDA $08         ; Pushing A?
         BPL C36BF7      ; Branch if not
         JSR C30F1D      ; Sound: Click
         TDC             ; Mode: Add
         JSR C36CD0      ; Add letter
         LDA $28         ; Arrow's column
         CMP #$05        ; Rightmost?
         BEQ C36BF4      ; Exit if so
         INC A           ; Go right by 1
C36BF4:  STA $28         ; Save changes
         RTS

; Fork: Handle B
C36BF7:  LDA $09         ; Pushing B?
         BPL C36C23      ; Exit if not
         JSR C30F32      ; Sound: Delete
         LDA $28         ; Arrow's column
         BEQ C36C23      ; Exit if first
         CMP #$05        ; Rightmost?
         BNE C36C17      ; Branch if not
         JSR C36CF7      ; Define Y
         LDA $0002,Y     ; Letter 6
         CMP #$FF        ; Blank?
         BEQ C36C17      ; Branch if so
         LDA #$FF        ; Mode: Delete V1
         BRA C36CD0      ; Delete letter 6

; Fork: Delete non-sixth letter
C36C17:  LDA #$01        ; Mode: Delete V2
         JSR C36CD0      ; Delete letter
         DEC $28         ; Move arrow left
C36C23:  RTS

; 60: Scroll to actor naming page 2 if valid starting point
C36C4A:  LDA $20         ; Timer expired?
         BEQ C36C66      ; Finalize if so
         LDA $4A         ; Bottom of P2?
         BNE C36C6C      ; Cancel if so
         REP #$21        ; 16-bit A; C-
         LDA $7E9BCD     ; BG1 V-Shift
         ADC #$0008      ; Go 8 px down
         BRA C36CB_      ; Set for charset

; Fork: Restore control
C36C66:  LDA #$64        ; Chars per page
         STA $4A         ; Set tbl index
         STZ $4E         ; Cursor row: 1
C36C6C:  LDA #$5F        ; C3/656C
         STA $26         ; Next: Resume
         RTS

; 61: Scroll to actor naming page 1 if valid starting point
C36C71:  LDA $20         ; Timer expired?
         BEQ C36C8E      ; Finalize if so
         LDA $4A         ; Top of page 1?
         BEQ C36C94      ; Cancel if so
         REP #$20        ; 16-bit A
         LDA $7E9BCD     ; BG1 V-Shift
         SEC             ; Prepare SBC
         SBC #$0008      ; Go 8 px up
         BRA C36CB_      ; Set for charset

; Fork: Restore control
C36C8E:  STZ $4A         ; Char tbl index
         LDA #$09        ; Row: Last
         STA $4E         ; Set cursor's
C36C94:  LDA #$5F        ; C3/656C
         STA $26         ; Next: Resume
         RTS

; Handle L and R for actor naming menu
C36C99:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BEQ C36CCF      ; Exit if not
         JSR C30F0E      ; Sound: Cursor
         LDA $4A         ; On page 2?
         BNE C36CBE      ; Branch if so

; Fork: Switch to page 2
C36CAA:  LDA #$64        ; Chars per page
         STA $4A         ; Set tbl index
         REP #$20        ; 16-bit A
         LDA #$0070      ; BG1 V-Shift: 112
         BRA C36CB_      ; Set for charset

; Fork: Switch to page 1
C36CBE:  STZ $4A         ; Char tbl index
         REP #$20        ; 16-bit A
         LDA #$FFD0      ; BG1 V-Shift: -48
C36CB_:  STA $7E9BCD     ; For upper chars
         STA $7E9BD0     ; For lower chars
         SEP #$20        ; 8-bit A
C36CCF:  RTS

; Add or remove letter from actor name
C36CD0:  PHA             ; Save mode
         JSR C36CF7      ; Define Y
         PLA             ; Deleting 6th?
         BMI C36CE2      ; Branch if so
         BEQ C36CE8      ; Branch if adding
         LDA #$FF        ; Char: Terminator
         STA $0001,Y     ; Clear last letter
         RTS

; Fork: Delete letter 6
C36CE2:  LDA #$FF        ; Char: Terminator
         STA $0002,Y     ; Clear letter 6
         RTS

; Fork: Add selected letter
C36CE8:  TDC             ; Clear A
         LDA $4B         ; Selected slot
         CLC             ; Prepare ADC
         ADC $4A         ; +100 if page 2
         TAX             ; Index sum
         LDA.L !anm_ct,X ; Chosen letter
         STA $0002,Y     ; Add to name
         RTS

; Get index for overwritten letter in actor naming menu
C36CF7:  LDY $67         ; Actor's address
         LDA $28         ; Arrow column
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         ADC $E7         ; Add column
         TAY             ; Put sum in Y
         SEP #$20        ; 8-bit A
         RTS

; Initialize arrow's column for actor naming menu
C36D09:  LDX $67         ; Actor's address
         LDY $00         ; Column: 1st
C36D0D:  LDA $02,X       ; Current letter
         INC A           ; Terminator?
         BEQ C36D1C      ; Branch if so
         INX             ; Point to next
         INY             ; Arrow column +1
         CPY #$0006      ; Done 6 letters?
         BNE C36D0D      ; Loop if not
         DEY             ; Column: 6th
C36D1C:  TYA             ; Move column to A
         STA $28         ; Set arrow column
         RTS

; Handle D-Pad for actor naming menu
C36D26:  JSR C307B0      ; Handle D-Pad
C36D29:  LDY #C36D34     ; C3/6D34
         JMP C306C3      ; Relocate cursor

; Create portrait for actor naming menu
C36DFC:  LDY #C30B7D     ; C3/0B7D
         JSR qanim3      ; Queue OAM fn
         LDY #C30BF7     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         PEA $1010       ; Pos: 16, 16
         JMP C3F90Y      ; Set sprite's

; Draw actor naming menu
C36E29:  JSR C371BC      ; Clear BG2 map A
         LDX #C36E8C     ; C3/6E8C
         JSR boxes_      ; Upload windows
         JSR bg1c_cl     ; Clear BG1 A-C
         JSR C3D24D      ; Color: User's
         LDX #$385B      ; Tilemap ptr
         LDY.W #!anm_ct  ; D8/E8C8
         STY $E7         ; Set src LBs
         LDA.B #!anm_ct!h; Bank: D8
         STA $E9         ; Set src HB
         LDY $00         ; Src index: 0
         LDA #$10        ; Text rows: 16
         JSR C36EE6      ; Draw BG1a options
         LDX #$485B      ; Tilemap ptr
         LDA #$04        ; Text rows: 4
         JSR C36EE6      ; Draw BG1c options
         JSR C36E86      ; Draw actor name
         JSR C30E93      ; Upload BG1 A+B
         JSR C30EAF      ; Upload BG1 C+D
         JSR C371D0      ; Clear BG3 map A
         JMP C30ED9      ; Upload BG3 A+B

; Draw actor name for actor naming menu
C36E86:  LDY #$40E9      ; Text position
         JMP C3356A      ; Draw actor name

; Upload portrait for actor naming menu
C36E98:  LDX $67         ; Actor's address
         TDC             ; Clear A
         LDA $01,X       ; Graphics set
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA #$2600      ; $2600
         STA $2116       ; Set VRAM ptr
         LDA.L C376AF,X  ; GFX pointer
         TAX             ; Index it
         JSR C37794      ; Load portrait
         SEP #$20        ; 8-bit A
         RTS

; Load portrait colors for actor naming menu
C36EB3:  LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDY $67         ; Actor's address
         TDC             ; Clear A
         LDA $0001,Y     ; Graphics set
         TAX             ; Index it
         LDA.L C37694,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         LDY $00         ; RAM index: 0
C36ECC:  REP #$20        ; 16-bit A
         PHX             ; Save ROM index
         LDA $ED5860,X   ; Portrait color
         TYX             ; RAM index
         STA $7E3149,X   ; To OBJ pal 0
         SEP #$20        ; 8-bit A
         PLX             ; ROM index
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E3         ; One less color
         BNE C36ECC      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw options in actor naming menu
C36EE6:  STA $E5         ; Set row count
         STX $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
C36EEE:  LDA #$0A        ; Columns: 10
         STA $E6         ; Set counter
         LDX $00         ; RAM index: 0
C36EF4:  LDA [$E7],Y     ; Character
         STA $E0         ; Memorize it
         PHY             ; Save ROM index

; Fork: Character without diacritic
C36EF9:  CMP #$53        ; Normal char?
         BCC C36F03      ; Branch if not
         LDA #$FF        ; Space char
         STA $E1         ; Set diacritic
         BRA C36F23      ; Update tilemap

; Fork: Character with handakuten
C36F03:  CMP #$49        ; Bogus char?
         BCC C36F14      ; Branch if not
         LDA.B #!hnda    ; Mark: [°]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$17        ; Get true one
         STA $E0         ; Save changes
         BRA C36F23      ; Update tilemap

; Fork: Character with dakuten
C36F14:  CMP #$20        ; Roman range?
         BCC C36F23      ; Branch if not
         LDA.B #!daku    ; Mark: ["]
         STA $E1         ; Set diacritic
         LDA $E0         ; Letter number
         CLC             ; Prepare ADC
         ADC #$40        ; Get true one
         STA $E0         ; Save changes

; Fork: Add character to tilemap
C36F23:  TXY             ; Base RAM index
         LDA $E1         ; Diacritic
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         REP #$21        ; 16-bit A; C-
         TXA             ; Base RAM index
         ADC #$0040      ; Go 1 row down
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $E0         ; Base character
         STA [$EB],Y     ; Add to tilemap
         INY             ; Index +1
         LDA $29         ; Palette, etc.
         STA [$EB],Y     ; Set attributes
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PLY             ; ROM index
         INY             ; ROM index +1
         LDA $E6         ; Columns left
         CMP #$06        ; At separator?
         BNE C36F4E      ; Branch if not
         INX             ; RAM index +1
         INX             ; RAM index +1
C36F4E:  DEC $E6         ; One less column
         BNE C36EF4      ; Loop till last
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Tilemap ptr
         ADC #$0080      ; +2 rows down
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         DEC $E5         ; One less row
         BNE C36EEE      ; Loop till last
         RTS

; Set to condense text in actor naming menu
C36F63:  LDX #$000C      ; Base index
C36F65:  LDA.L C36FBD,X  ; BG1 V-Pan data
         STA $7E9BC9,X   ; Save in RAM
         DEX             ; Index -1
         BPL C36F65      ; Loop till < 0
         LDY #$9BC9      ; Src: 7E/9BC9
         JSR bg1v_       ; Queue BG1 V-Pan
         LDY #C36FB0     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1h        ; Queue BG1 H-Pan

; Update large arrow in actor naming menu
C36FCA:  BNE C36FF5      ; If mode 1

; Mode 0: Initialize arrow
C36FD2:  LDY #C37015     ; Anim table ptr
         JSR anm_c3      ; Set arrow's
         LDY #$2890      ; Pos: 144, 40
         JSR objpos      ; Set arrow's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C36FF5:  TXY             ; Queue index
         LDX $00         ; Arrow: Down
         LDA $4A         ; On first page?
         BEQ C36FFF      ; Branch if so
         INX #2          ; Arrow: Up
C36FFF:  REP #$20        ; 16-bit A
         LDA.L C37011,X  ; Anim table ptr
         STA $32C9,Y     ; Set arrow's
         JMP oamsec      ; Set OAM; requeue

; Update small arrow in actor naming menu
C3702C:  BNE C37054      ; If mode 1

; Mode 0: Initialize arrow
C37034:  LDY #C3C34E     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         LDA #$20        ; Y: 32
         STA $344A,X     ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C37054:  TXY             ; Queue index
         TDC             ; Clear A
         LDA $28         ; Arrow's slot
         TAX             ; Index it
         LDA.L C37066,X  ; X position
         STA $33CA,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Reset menu or ending variables
C3706C:  JSL $D4CDF3     ; Reset many vars
         JSR C37076      ; Reset BGs' X/Y
         JMP C3B0D9      ; Clear VWF GFX

; Reset BG positions
C37076:  LDY $00         ; Clear Y
         STY $35         ; BG1 X-Loc: 0
         STY $39         ; BG2 X-Loc: 0
         STY $3D         ; BG3 X-Loc: 0
         STY $37         ; BG1 Y-Loc: 0
         STY $3B         ; BG2 Y-Loc: 0
         STY $3F         ; BG3 Y-Loc: 0
         STY $41         ; List V-Spd: 0
         RTS

; Get party info from SRAM block
C37087:  JSL $D4CA00     ; Clear all info
         TDC             ; Clear A
         TAY             ; 1st: Terra
C3708E:  LDA $1850,Y     ; Party info
         BIT #$40        ; Object's off?
         BEQ C370B3      ; Skip if so
         AND #$07        ; Get party
         CMP $1A6D       ; Active party?
         BNE C370B3      ; Skip if not
         LDA $1850,Y     ; Party info
         PHA             ; Memorize it
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAX             ; Index it
         PLA             ; Party info
         STA $75,X       ; Set member's
         TYA             ; Actor slot
         STA $69,X       ; Set member's
C370B3:  INY             ; Actor slot +1
         CPY #$0010      ; Done 16 chars?
         BNE C3708E      ; Loop if not
         LDY $00         ; 1st: Member 1
C370BB:  TDC             ; Clear A
         LDA $0069,Y     ; Actor
         CMP #$FF        ; Empty slot?
         BEQ C370D4      ; Skip if so
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor's address
         PHA             ; Memorize it
         TYA             ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         PLA             ; SRAM address
         STA $6D,X       ; Set member's
         SEP #$20        ; 8-bit A
C370D4:  INY             ; Member slot +1
         CPY #$0004      ; Done 4 slots?
         BNE C370BB      ; Loop if not
         RTS

; SRAM block addresses for actor data
C370DB:  dw $1600        ; 00: Terra
         dw $1625        ; 01: Locke
         dw $164A        ; 02: Cyan
         dw $166F        ; 03: Shadow
         dw $1694        ; 04: Edgar
         dw $16B9        ; 05: Sabin
         dw $16DE        ; 06: Celes
         dw $1703        ; 07: Strago
         dw $1728        ; 08: Relm
         dw $174D        ; 09: Setzer
         dw $1772        ; 0A: Mog
         dw $1797        ; 0B: Gau
         dw $17BC        ; 0C: Gogo
         dw $17E1        ; 0D: Umaro
         dw $1806        ; 0E: Guest 1
         dw $182B        ; 0F: Guest 2

; Copy party info to SRAM block
C370FB:  LDX #$0003      ; 1st: Member 4
C370FE:  LDA $69,X       ; Actor in slot
         BMI C37114      ; Skip if nobody
         TAY             ; Index it
         LDA $75,X       ; Party info
         AND #$E7        ; Clear roster slot
         STA $E0         ; Memorize info
         TXA             ; Member slot
         ASL A           ; Put in b1-b2
         ASL A           ; Put in b2-b3
         ASL A           ; Put in b3-b4
         ORA $E0         ; Add saved info
         STA $1850,Y     ; Put in SRAM area
C37114:  DEX             ; Member slot -1
         BPL C370FE      ; Loop till last
         RTS

; Memorize current party (useless)
C3711B:; REP #$20        ; 16-bit A
       ; LDA $69         ; Members 1 and 2
       ; STA $7EAA89     ; Memorize them
       ; LDA $6B         ; Members 3 and 4
       ; STA $7EAA8B     ; Memorize them
       ; SEP #$20        ; 8-bit A
       ; RTS

; Draw multiple strings without diacritics
C3712C:  PHA             ; Save counter
         PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA.L C30000,X  ; Text pointer
         TAY             ; Set src LBs
         JSR C302F9      ; Draw string
         PLX             ; String index
         INX             ; Index +1
         INX             ; Index +1
         PLA             ; Strings left
         DEC A           ; One less left
         BNE C3712C      ; Loop till last
         RTS

; Draw multiple strings with diacritics but without Roman characters
C3714E:  PHA             ; Save counter
         PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA.L C30000,X  ; Text pointer
         TAY             ; Set src LBs
         JSR C30326      ; Draw string
         PLX             ; String index
         INX             ; Index +1
         INX             ; Index +1
         PLA             ; Strings left
         DEC A           ; One less left
         BNE C3714E      ; Loop till last
         RTS

; Set Window 1 positions per scanline
C37170:  LDA #$01        ; 2Rx1B to PPU
         STA $4320       ; Set CH2 mode
         LDA #$26        ; $2126, $2127
         STA $4321       ; To Win 1 L+R
         LDY #C3718F     ; C3/718F
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Window 1 positions per scanline
C3718F:  db $07,$FF,$00  ; No range
         db $78,$08,$F7  ; 8, 247
         db $58,$08,$F7  ; 8, 247
         db $08,$FF,$00  ; No range
         db $00          ; End

; Set global Window 1 positions
C3719C:  LDA #$04        ; Channel: 2
         TRB $43         ; Halt Win1 HDMA
         LDX #$FF00      ; Win1-L: 0
         STX $2126       ; Win1-R: 255
         RTS

; Clear BG1 tilemap A
C371A9:  LDX #$3849      ; 7E/3849
         BRA C371E2      ; Clear map

; Clear BG1 tilemap B
C371AD:  LDX #$4049      ; 7E/4049
         BRA C371E2      ; Clear map

; Clear BG1 tilemap C
C371B2:  LDX #$4849      ; 7E/4849
         BRA C371E2      ; Clear map

; Clear BG1 tilemap D
C371B7:  LDX #$5049      ; 7E/5049
         BRA C371E2      ; Clear map

; Clear BG2 tilemap A
C371BC:  LDX #$5849      ; 7E/5849
         BRA C371E2      ; Clear map

; Clear BG2 tilemap B
C371C1:  LDX #$6049      ; 7E/6049
         BRA C371E2      ; Clear map

; Clear BG2 tilemap C
C371C6:  LDX #$6849      ; 7E/6849
         BRA C371E2      ; Clear map

; Clear BG2 tilemap D (unused)
C371CB:  LDX #$7049      ; 7E/7049
         BRA C371E2      ; Clear map

; Clear BG3 tilemap A
C371D0:  LDX #$7849      ; 7E/7849
         BRA C371E2      ; Clear map

; Clear BG3 tilemap B
C371D5:  LDX #$8049      ; 7E/8049
         BRA C371E2      ; Clear map

; Clear BG3 tilemap C
C371DA:  LDX #$8849      ; 7E/8849
         BRA C371E2      ; Clear map

; Clear BG3 tilemap D
C371DF:  LDX #$9049      ; 7E/9049
C371E2:  LDY #$0800      ; Bytes: 2048
         JMP clr_ram     ; Clear map

; Load graphics, colors, enemy, and prize for Colosseum matchup
C371FA:  JSR C372A7      ; BG3 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor/VS GFX
         JSR C3745B      ; Actor colors
         JSR C37418      ; Cursor/VS colors
         JSR C3747D      ; Actor sprites
         JSR C3B8B3      ; Prize/enemy data
         JMP C3BCB8      ; Arena

; Load non-skin graphics and colors for menu
C3721B:  TDC             ; Clear A
         LDA $0200       ; Menu
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C37224,X)  ; Load data

; Jump table for the above
C37224:  dw C3727D       ; Main menu
         dw C37298       ; Actor naming
         dw C3727D       ; Load menu
         dw C37262       ; Shop
         dw C37244       ; Lineup
         dw C37244       ; Bogus...
         dw C37238       ; SwdTech naming
         dw C3727D       ; Colosseum
         dw C37244       ; Final battle lineup

; Load graphics and colors for SwdTech naming menu
C37238:  JSR C372CB      ; BG1 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor/arrow GFX
         JMP C37418      ; Their colors

; Load graphics and colors for Lineup or final battle menu
C37244:  JSR C377A4      ; Blank portrait
         JSR C372A7      ; BG3 font GFX
         JSR C372CB      ; BG1 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor/icon GFX
         JSR C3745B      ; Actor colors
         JSR C37418      ; Cursor/icon pals
         JMP C3747D      ; Actor sprites

; Load graphics and colors for shop menu
C37262:  JSR C372A7      ; BG3 font GFX
         JSR C372CB      ; BG1 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor/icon GFX
         JSR C3745B      ; Actor colors
         JSR C37418      ; Cursor/icon pals
         JMP C3750D      ; Actor sprites

; Load graphics and colors for Load, Main, or Colosseum menu
C3727D:  JSR C372A7      ; BG3 font GFX
         JSR C372CB      ; BG1 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor/icon GFX
         JSR C37616      ; Portrait GFX
         JSR C3739D      ; Portrait colors
         JSR C3747D      ; Actor sprites
         JSR C37418      ; Cursor/icon pals
         JMP C373F4      ; Grayscale pal

; Load graphics and colors for actor naming menu
C37298:  JSR C372A7      ; Blank BG tile
         JSR C372CB      ; BG1 font GFX
         JSR C3737C      ; Font colors
         JSR C375FB      ; Cursor GFX
         JMP C37418      ; Cursor colors

; Upload BG3 font graphics and erase VWF description
C372A7:  REP #$20        ; 16-bit A
         LDY #$6000      ; $6000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C372B1:  LDA $C47FC0,X   ; Font graphics
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1000      ; 256th tile?
         BNE C372B1      ; Loop if not
C372BF:  STA $2118       ; Clear desc GFX
         INX             ; Index +1
         CPX #$1400      ; 128th tile?
         BNE C372BF      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload BG1 font graphics
C372CB:  LDY #$5000      ; $5000
         STY $2116       ; Set VRAM ptr
         REP #$20        ; 16-bit A
         TDC             ; Clear A
         TAX             ; Index: 0
C372D5:  LDY #$0008      ; 8-px rows: 8
C372D8:  LDA.L C37330,X  ; Square GFX
         STA $2118       ; Save in VRAM
         DEY             ; One less row
         BNE C372D8      ; Loop till last
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 8 tiles?
         BNE C372D5      ; Loop if not
         LDX $00         ; Index: 0
C372EB:  LDY #$0008      ; 8-px rows: 8
C372EE:  LDA $C48040,X   ; Font GFX row
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less row
         BNE C372EE      ; Loop till last
         LDY #$0008      ; 8-px rows: 8
.loop    STZ $2118       ; Planes C and D
         DEY             ; One less row
         BNE .loop       ; Loop till last
         CPX #$0F80      ; 248th tile?
         BNE C372EB      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Square BG1 tiles, encoded as a single row
C37330:  dw $0000,$0000  ; Blank tile
         dw $00FF,$0000  ; Config: Palette color 1
         dw $FF00,$0000  ; Config: Palette color 2
         dw $FFFF,$0000  ; Config: Palette color 3
         dw $0000,$00FF  ; Config: Palette color 4
         dw $00FF,$00FF  ; Config: Palette color 5
         dw $FF00,$00FF  ; Config: Palette color 6
         dw $FFFF,$00FF  ; Config: Palette color 7

; Reset all skin colors
C37350:  LDX #$0008      ; Skins left: 8
         STX $E7         ; Set counter
         LDX $00         ; ROM index: 0
         TXY             ; RAM index: 0
         REP #$20        ; 16-bit A
C3735B:  LDA #$0007      ; Colors left: 7
         STA $E9         ; Set counter
C37360:  LDA $ED1C02,X   ; Default color
         STA $1D57,Y     ; Save in options
         INX             ; ROM index +1
         INX             ; ROM index +1
         INY             ; RAM index +1
         INY             ; RAM index +1
         DEC $E9         ; One less color
         BNE C37360      ; Loop till last
         TXA             ; ROM index
         CLC             ; Prepare ADC
         ADC #$0012      ; Reach next skin
         TAX             ; Reindex it
         DEC $E7         ; One less skin
         BNE C3735B      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load font and black background's colors
C3737C:  STZ $2121       ; To BG color 0
         LDX $00         ; Color index: 0
C37382:  REP #$20        ; 16-bit A
         LDA $D8E800,X   ; BG color
         STA $7E3049,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$00A0      ; Done 80 colors?
         BNE C37382      ; Loop if not
         RTS

; Load portrait colors for entire party
C3739D:  LDX $00         ; Member index: 0
         TXY             ; Dest index: 0
C373A0:  PHX             ; Save member index
         PHY             ; Save dest index
         LDY $6D,X       ; Actor data index
         TDC             ; Clear A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C373B9      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C373C4      ; Ignore actor
C373B9:  LDA $0000,Y     ; Actor
         CMP #$01        ; Locke?
         BEQ C373C4      ; Branch if so
         LDA $0001,Y     ; Graphics set
C373C4:  TAX             ; Index it
         LDA.L C37694,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         PLY             ; RAM index
         JSR C36ECC      ; Load palette
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C373A0      ; Loop if not
         RTS

; Load grayscale actor palette
C373F4:  LDA #$90        ; Object color 16
         STA $2121       ; CGRAM: $0120
         LDX $00         ; Color index: 0
C373FB:  REP #$20        ; 16-bit A
         LDA $D8E8A0,X   ; Grayscale color
         STA $7E3169,X   ; To OBJ pal 1
         JSR cgram       ; Save in CGRAM
         CPX #$0020      ; Done 16 colors?
         BNE C373FB      ; Loop if not
         RTS

; Load cursor, arrow, and icon colors
C37418:  LDX $00         ; Color index: 0
         LDA #$EC        ; Object color 108
         STA $2121       ; CGRAM: $01D8
C3741F:  REP #$20        ; 16-bit A
         LDA $D8E8C0,X   ; Status icon color
         STA $7E3221,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0008      ; Done 4 colors?
         BNE C3741F      ; Loop if not
         LDX $00         ; Color index: 0
         LDA #$FC        ; Object color 124
         STA $2121       ; CGRAM: $01F8
C37440:  REP #$20        ; 16-bit A
         LDA $D8E8B8,X   ; Cursor, etc. color
         STA $7E3241,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$0008      ; Done 4 colors?
         BNE C37440      ; Loop if not
         RTS

; Load actor sprite palettes
C3745B:  LDA #$A0        ; Object color 32
         STA $2121       ; CGRAM: $0140
         LDX $00         ; Color index: 0
C37462:  REP #$20        ; 16-bit A
         LDA $ED6300,X   ; Sprite color
         STA $7E3189,X   ; Save in RAM
         JSR cgram       ; Save in CGRAM
         CPX #$00C0      ; Done 96 colors?
         BNE C37462      ; Loop if not
         RTS

; Upload actor sprite graphics (one pose)
C3747D:  TDC             ; Clear A
         TAX             ; OBJ index: 0
C3747F:  PHX             ; Save index
         REP #$20        ; 16-bit A
         LDA $CFF895,X   ; VRAM pointer
         STA $F3         ; Memorize it
         TXA             ; Sprite index
         ASL A           ; Double it
         TAX             ; Index it
         LDA $CFF8C3,X   ; GFX adr LBs
         STA $E7         ; Memorize it
         LDA $CFF8C1,X   ; GFX adr HBs
         STA $E9         ; Memorize it
         LDX $00         ; Ptr index: 0

; Fork: Head and torso
C37499:  LDA $CFF88F,X   ; Tile rel ptr
;        STA $EF         ; Memorize it
         JSR C374D8      ; Load 2 tiles
         INC $F4         ; VRAM: +1 row
         INX             ; Ptr index +1
         INX             ; Ptr index +1
         CPX #$0004      ; Done 2 rows?
         BNE C37499      ; Loop if not

; Fork: Legs
C374B1:  LDA $F3         ; VRAM pointer
         SEC             ; Prepare SBC
         SBC #$01E0      ; Row -2, col +2
         STA $F3         ; Save changes
         LDA $CFF88F,X   ; Tile rel ptr
;        STA $EF         ; Memorize it
         JSR C374D8      ; Load leg GFX

; Fork: Blank row
C374C2:  INC $F4         ; VRAM: +1 row
         JSR C374FB      ; Blank 4th row

; Fork: Handle next sprite
C374CD:  PLX             ; Sprite index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$002C      ; 22th sprite?
         BNE C3747F      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload both tiles in current row of actor sprite
C374D8:  CLC             ; Prepare ADC
;        LDA $EF         ; Tile rel pointer
         ADC $E7         ; Add base adr LBs
         STA $EB         ; Set src LBs
         TDC             ; Zero A
         ADC $E9         ; Add adr HBs + C
         STA $ED         ; Set source HBs
         LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
C374EC:  LDY $00         ; Index: 0
C374EE:  LDA [$EB],Y     ; Tile graphics
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0040      ; Done 2 tiles?
         BNE C374EE      ; Loop if not
         RTS

; Blank both tiles under actor's feet
C374FB:  LDY $F3         ; VRAM pointer
         STY $2116       ; Set destination
         LDA #$0020      ; Tiles: 2
         JMP C3BA80      ; Create tiles

; Upload actor sprites for shop
C3750D:  LDY #$3000      ; $3000
         STY $2116       ; Set VRAM ptr
         STZ $E3         ; Actor slot: 1

; Fork: Load both poses for two actors
C37515:  LDY $00         ; Tile slot: 1
C37517:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         TYX             ; Tile slot
         LDA.L C3759B,X  ; GFX ptr index
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C375BB,X  ; Tile's GFX ptr
         CMP #$FFFF      ; Blank tile?
         BEQ C3757E      ; Blank if so
         PHY             ; Save tile slot
         PHA             ; Save pointer
         SEP #$20        ; 8-bit A
         LDA $E3         ; Actor A's slot
         LDY #$16A0      ; GFX struct size
         JSR mul16       ; Slot x size
         REP #$21        ; 16-bit A; C-
         PLA             ; Tile GFX ptr
         ADC $2134       ; Add product LBs
         STA $EB         ; Set source LBs
         SEP #$20        ; 8-bit A
         LDA $2136       ; Product HB
         ADC #$D5        ; Add base bank
         STA $ED         ; Set source HB
         REP #$20        ; 16-bit A
         JSR C3758C      ; Load tile's GFX
         PLY             ; Tile slot
C3756B:  INY             ; Tile slot +1
         CPY #$0020      ; Done 32 tiles?
         BNE C37517      ; Loop if not

; Fork: Handle next two actors
C37571:  SEP #$20        ; 8-bit A
         INC $E3         ; Actor slot +1
         INC $E3         ; Actor slot +1
         LDA $E3         ; Actor slot
         CMP #$10        ; Handled 16?
         BNE C37515      ; Loop if not
         RTS

; Fork: Create a blank tile
C3757E:  JSR C3BA77      ; Create tile
         BRA C3756B      ; Do next tile

; Upload current actor sprite tile for shop
C3758C:  LDY $00         ; Index: 0
C3758E:  LDA [$EB],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY #$0020      ; Done 8 rows?
         BNE C3758E      ; Loop if not
         RTS

; Indices for loading tiles from two shop actors
C3759B:  db $00          ; Actor1 X1,Y1 (hands down)
         db $01          ; Actor1 X1,Y2 (hands down)
         db $04          ; Actor1 X3,Y1 (hands down)
         db $05          ; Actor1 X3,Y2 (hands down)
         db $08          ; Actor1 X1,Y1 (hands up)
         db $09          ; Actor1 X1,Y2 (hands up)
         db $0C          ; Actor1 X3,Y1 (hands up)
         db $0D          ; Actor1 X3,Y2 (hands up)
         db $10          ; Actor2 X1,Y1 (hands down)
         db $11          ; Actor2 X1,Y2 (hands down)
         db $14          ; Actor2 X3,Y1 (hands down)
         db $15          ; Actor2 X3,Y2 (hands down)
         db $18          ; Actor2 X1,Y1 (hands up)
         db $19          ; Actor2 X1,Y2 (hands up)
         db $1C          ; Actor2 X3,Y1 (hands up)
         db $1D          ; Actor2 X3,Y2 (hands up)
         db $02          ; Actor1 X2,Y1 (hands down)
         db $03          ; Actor1 X2,Y2 (hands down)
         db $06          ; Actor1 X4,Y1 (hands down)
         db $07          ; Actor1 X4,Y2 (hands down)
         db $0A          ; Actor1 X2,Y1 (hands up)
         db $0B          ; Actor1 X2,Y2 (hands up)
         db $0E          ; Actor1 X4,Y1 (hands up)
         db $0F          ; Actor1 X4,Y2 (hands up)
         db $12          ; Actor2 X2,Y1 (hands down)
         db $13          ; Actor2 X2,Y2 (hands down)
         db $16          ; Actor2 X4,Y1 (hands down)
         db $17          ; Actor2 X4,Y2 (hands down)
         db $1A          ; Actor2 X2,Y1 (hands up)
         db $1B          ; Actor2 X2,Y2 (hands up)
         db $1E          ; Actor2 X4,Y1 (hands up)
         db $1F          ; Actor2 X4,Y2 (hands up)

; Tile graphics pointers for odd-numbered shop actors
C375BB:  dw $03C0        ; 1,1 (hands down)
         dw $03E0        ; 1,2 (hands down)
         dw $0500        ; 2,1 (hands down)
         dw $0520        ; 2,2 (hands down)
         dw $0540        ; 3,1 (hands down)
         dw $0560        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $03C0        ; 1,1 (hands up)
         dw $0660        ; 1,2 (hands up)
         dw $0680        ; 2,1 (hands up)
         dw $06A0        ; 2,2 (hands up)
         dw $06C0        ; 3,1 (hands up)
         dw $06E0        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Tile graphics pointers for even-numbered shop actors
C375DB:  dw $1A60        ; 1,1 (hands down)
         dw $1A80        ; 1,2 (hands down)
         dw $1BA0        ; 2,1 (hands down)
         dw $1BC0        ; 2,2 (hands down)
         dw $1BE0        ; 3,1 (hands down)
         dw $1C00        ; 3,2 (hands down)
         dw $FFFF        ; 4,1 (hands down)
         dw $FFFF        ; 4,2 (hands down)
         dw $1A60        ; 1,1 (hands up)
         dw $1D00        ; 1,2 (hands up)
         dw $1D20        ; 2,1 (hands up)
         dw $1D40        ; 2,2 (hands up)
         dw $1D60        ; 3,1 (hands up)
         dw $1D80        ; 3,2 (hands up)
         dw $FFFF        ; 4,1 (hands up)
         dw $FFFF        ; 4,2 (hands up)

; Upload cursor, arrow, and icon graphics (plus excess data)
C375FB:  REP #$20        ; 16-bit A
         LDY #$2000      ; $2000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; Index: 0
C37605:  LDA $ED5AC0,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX #$1400      ; At ED/6EC0?
         BNE C37605      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Upload each member's portrait
C37616:  LDX $00         ; 1st: Member 1
C37618:  REP #$20        ; 16-bit A
         LDA.L C376E5,X  ; VRAM pointer
         STA $2116       ; Set destination
         PHX             ; Save mbr index
         LDY $6D,X       ; Actor's address
         JSR faceptr     ; GFX pointer
         TAX             ; Index it
         JSR C37794      ; Upload portrait
         PLX             ; Member index
         INX             ; Member index +1
         INX             ; Member index +1
         CPX #$0008      ; Done 4 members?
         BNE C37618      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Set to upload healed member's portrait
C37653:  LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $9C         ; Member slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C376E5,X  ; VRAM pointer
         STA $1B         ; Set destination
         LDY $6D,X       ; Actor's address
         JSR faceptr     ; GFX pointer
;        CLC             ; ...
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         RTS

; Portrait palette assignments
C37694:  db $00          ; 00: Terra
         db $01          ; 01: Locke
         db $02          ; 02: Cyan
         db $03          ; 03: Shadow
         db $04          ; 04: Edgar
         db $05          ; 05: Sabin
         db $06          ; 06: Celes
         db $07          ; 07: Strago
         db $08          ; 08: Relm
         db $09          ; 09: Setzer
         db $0A          ; 0A: Moogle
         db $0B          ; 0B: Gau
         db $0C          ; 0C: Gogo
         db $0D          ; 0D: Umaro
         db $0E          ; 0E: Soldier
         db $0F          ; 0F: Imp
         db $10          ; 10: Leo
         db $11          ; 11: Banon
         db $00          ; 12: Terra (unused; esper Terra)
         db $0E          ; 13: Soldier (unused; merchant)
         db $12          ; 14: Ghost
;        db $00          ; 15: Terra (unused; Kefka)
;        db $00          ; 16: Terra (unused; Gestahl)
;        db $00          ; 17: Terra (unused; Gungho)
;        db $00          ; 18: Terra (unused; Duane)
;        db $00          ; 19: Terra (unused; dog)
;        db $06          ; 1A: Celes (unused; Maria)

; Pointers to portrait graphics
C376AF:  dw $0000        ; 00: Terra
         dw $0320        ; 01: Locke
         dw $0640        ; 02: Cyan
         dw $0960        ; 03: Shadow
         dw $0C80        ; 04: Edgar
         dw $0FA0        ; 05: Sabin
         dw $12C0        ; 06: Celes
         dw $15E0        ; 07: Strago
         dw $1900        ; 08: Relm
         dw $1C20        ; 09: Setzer
         dw $1F40        ; 0A: Mog
         dw $2260        ; 0B: Gau
         dw $2580        ; 0C: Gogo
         dw $28A0        ; 0D: Umaro
         dw $2BC0        ; 0E: Soldier
         dw $2EE0        ; 0F: Imp
         dw $3200        ; 10: Leo
         dw $3520        ; 11: Banon
         dw $0000        ; 12: Terra (unused; esper Terra)
         dw $2BC0        ; 13: Soldier (unused; merchant)
         dw $3840        ; 14: Ghost
;        dw $0000        ; 15: Terra (unused; Kefka)
;        dw $0000        ; 16: Terra (unused; Gestahl)
;        dw $0000        ; 17: Terra (unused; Gungho)
;        dw $0000        ; 18: Terra (unused; Duane)
;        dw $0000        ; 19: Terra (unused; dog)
;        dw $12C0        ; 1A: Celes (unused; Maria)

; VRAM pointers for portrait graphics
C376E5:  dw $2600        ; Member 1
         dw $2800        ; Member 2
         dw $2A00        ; Member 3
         dw $2C00        ; Member 4
;        dw $2E00        ; Bogus...
;        dw $3000        ; Bogus...
;        dw $3200        ; Bogus...
;        dw $3400        ; Bogus...

; List actor sprites for save file 1
C376F5:  LDY $91         ; File checksum
         LDX #$AA71      ; List address
         BRA C3777_      ; Build list

; List actor sprites for save file 2
C3774C:  LDY $93         ; File checksum
         LDX #$AA75      ; List address
         BRA C3777_      ; Build list

; List actor sprites for save file 3
C37770:  LDY $95         ; File checksum
         LDX #$AA79      ; List address
C3777_:  STX $2181       ; Set WRAM LBs
         CPY $00         ; Blank file?
         BEQ C3778F      ; Nobody if so
         LDX $00         ; Member slot: 1
C37776:  LDA $69,X       ; Actor in slot
         BMI C37782      ; Blank if none
         JSR C3772B      ; Get sprite set
         JSR C3773A      ; Handle soldier
         BRA C37784      ; Skip a line
C37782:  LDA #$FF        ; Sprite: None
C37784:  STA $2180       ; Set sprite
         INX             ; Member slot +1
         CPX #$0004      ; Done all 4?
         BNE C37776      ; Loop if not
         RTS

; Fork: Empty party
C3778F:  LDX #$0004      ; Members: 4
         LDA #$FF        ; Sprite: None
.loop    STA $2180       ; Set member's
         DEX             ; One less left
         BPL .loop       ; Loop till last
         RTS

; Get actor's graphics set
C3772B:  PHX             ; Save X
         REP #$20        ; 16-bit A
         TXA             ; Actor number
         JSR C32DA_      ; Define Y
         SEP #$20        ; 8-bit A
         PLX             ; Restore X
         LDA $0001,Y     ; Graphics set
         RTS

; Choose between green or brown soldier
C3773A:  CMP #$0E        ; Soldier sprite?
         BNE C3774B      ; Exit if not
         LDA $1EA0       ; Event flags
         BIT #$08        ; Soldier disguise?
         BEQ C37749      ; Pick brown if not
         LDA #$16        ; Use green soldier
         RTS             ; Exit
C37749:  LDA #$0E        ; Use brown soldier
C3774B:  RTS

; Upload actor's portrait graphics
C37794:  LDY #$0190      ; Tiles: 25
C37797:  LDA $ED1D00,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         DEY             ; One less word
         BNE C37797      ; Loop till last
         RTS

; Create a blank portrait for Lineup menu
C377A4:  LDX #$9F51      ; 7E/9F51
         LDY #$0320      ; Tiles: 25
         JMP clr_ram     ; Clear data

; Validate SRAM markers
C377B7:  PHB             ; Save DB
         LDA #$30        ; Bank: 30
         PHA             ; Put on stack
         PLB             ; Set DB to 30
         LDX #$E41B      ; Square's marker
         CPX $7FF8       ; In file A?
         BEQ C377DB      ; Okay if so
         CPX $7FFA       ; In file B?
         BEQ C377DB      ; Okay if so
         CPX $7FFC       ; In file C?
         BEQ C377DB      ; Okay if so
         CPX $7FFE       ; In file D?...
         BNE C377DF      ; Delete if not
C377DB:  PLB             ; Restore DB
         SEC             ; Call Load menu
         RTS

; Fork: Delete all saved data
C377DF:  REP #$20        ; 16-bit A
         LDX $00         ; SRAM index: 0
C377E9:  STZ $6000,X     ; Clear SRAM word
         INX             ; Index +1
         INX             ; Index +1
         CPX #$2000      ; Fully cleared?
         BNE C377E9      ; Loop if not
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         CLC             ; Skip Load menu
         RTS

; Reset saved cursor positions for main menu
C377FC:  JSR C34DE9      ; Clear positions
         LDA #$01        ; Skills: "Magic"
         STA $0237       ; Set for ally 1
         STA $0239       ; Set for ally 2
         STA $023B       ; Set for ally 3
         STA $023D       ; Set for ally 4
         RTS

; Mark all save files as Square's property
C37817:  REP #$20        ; 16-bit A
         LDA #$E41B      ; Square marker
         STA $307FF8     ; Mark file A
         STA $307FFA     ; Mark file B
         STA $307FFC     ; Mark file C
         STA $307FFE     ; No file D...
         SEP #$20        ; 8-bit A
         RTS

; Reset game data for Load menu
C3782F:  JSR C377FC      ; Clear cursor mem
         LDY #$7FFF      ; Color: White
         STY $1D55       ; Set user font's
         LDA #$12        ; Buttons: A & B
         STA $1D50       ; Define purpose
         LDA #$34        ; Buttons: X & Y
         STA $1D51       ; Define purpose
         LDA #$56        ; Buttons: L & R
         STA $1D52       ; Define purpose
         LDA #$06        ; Button: Select
         STA $1D53       ; Define purpose
         LDA #$2A        ; Bat.Mode, etc.
         STA $1D4D       ; Define options
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $1DC7       ; Save count: 0
         STZ $1D54       ; Mag.Order, etc.
         STZ $1D4E       ; Wallpaper, etc.
         STZ $1D4F       ; Pad assignments
         STY $1863       ; SRAM hours, mins
         STZ $1865       ; SRAM seconds
         STY $1860       ; Gold LBs
         STZ $1862       ; Gold HB
         STY $1866       ; Steps LBs
         STZ $1868       ; Steps HB
         STY $021B       ; Real hours, mins
         STY $021D       ; Real secs, frames
         JMP C37350      ; Reset skin colors

; 2C: Initialize Lineup menu
C3787B:  JSR C37890      ; Init variables
         STZ $4A         ; Cursor area: Top
         JSR C37DBE      ; List/Create actors
         JSR C37C16      ; Load navig data
         JSR C37C1F      ; Relocate cursor
         BRA C378A8      ; Draw menu, etc.

; Initialize variables for Lineup menu
C37890:  JSR C335F7      ; Reset/Stop stuff
         JSR C37076      ; Reset BGs' X/Y
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         RTS

; Draw Lineup menu, etc.
C378A8:  JSR C30833      ; Queue cursor OAM
         JSR C37D59      ; Set to shift text
         JSR C37CB6      ; Draw boxes/title
         JSR C380D3      ; Create portrait
         JSR C380E7      ; Draw actor info
         JSR C30F68      ; Queue text upload
         LDA #$2D        ; C3/78FC
         STA $27         ; Queue: Choice 1
         LDA #$66        ; C3/8193
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 7D: Return to Lineup menu from Status menu
C378C5:  JSR C37890      ; Init variables
         LDA #$20        ; Channel: 5
         TRB $43         ; Halt HDMA-5
         JSR C37E0B      ; Create/lock chars
         BRA C378A8      ; Draw menu, etc.

; 2D: Handle Lineup menu choice 1
C378FC:  JSR C3794D      ; Cover D-Pad/stats
         BCC C37971      ; If crossed center
         LDA $08         ; Pushing A?
         BPL C3793D      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7EAC8D,X   ; Locked slot?
         BMI C37936      ; Fail if so
         JSR C30F1D      ; Sound: Click
         LDA $4B         ; Cursor slot
         STA $28         ; Set pick 1's
         LDA $4A         ; Cursor area
         STA $49         ; Set pick 1's
         LDA #$2E        ; C3/79A0
         STA $26         ; Next: Choice 2
         JMP C32FBC      ; Create blinker

; Fork: Forced member
C37936:  JMP C3C5C6      ; Buzzer + Mosaic

; Fork: Exit attempt
C3793D:  LDA $09         ; No-autofire keys
         BIT #$90        ; Using Start or B?
         BEQ C37971      ; Exit if not
         JMP C37A2A      ; Validate groups

; Handle D-Pad and update actor info in Lineup menu
C3794D:  JSR C37D4C      ; Update char info
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C37972      ; Branch if not
         LDA $4E         ; On row 1 or 3?
         BEQ C37972      ; Branch if so
         LDA $4A         ; In party area?
         BNE C37972      ; Branch if so

; Fork: Enter party area
C37960:  LDA #$10        ; Cursor slot: +16
         STA $4A         ; Set area mod
         JSR C37B6F      ; Relocate cursor
         JSR C30F0E      ; Sound: Cursor
         CLC             ; Mark area exit
C37971:  RTS

; Fork: Handle up
C37972:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3799A      ; Branch if not
         LDA $4E         ; On row 1 or 3?
         BNE C3799A      ; Branch if not
         LDA $4A         ; In party area?
         BEQ C3799A      ; Branch if not

; Fork: Exit party area
C37980:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         STZ $4A         ; Cursor area: Top
         JSR C37C16      ; Load navig data
         INC $4E         ; Cursor row: 2nd
         TDC             ; Clear A
         LDA $5E         ; Former column
         TAX             ; Index it
         LDA.L C37C0A,X  ; Intended column
         STA $4D         ; Set new column
         JSR C37C1F      ; Relocate cursor
         JSR C30F0E      ; Sound: Cursor
         CLC             ; Mark area exit
         RTS

; Fork: Staying within same area
C3799A:  JSR C37BA9      ; Handle D-Pad
         SEC             ; Unmark area exit
C3799F:  RTS

; 2E: Handle Lineup menu choice 2
C379A0:  JSR C3794D      ; Cover D-Pad/stats
         BCC C3799F      ; If crossed center
         LDA $08         ; Pushing A?
         BPL C37A11      ; Branch if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot B
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         STA $E0         ; Memorize sum
         TAX             ; Index it
         LDA $7EAC8D,X   ; Locked slot?
         BMI C37A23      ; Fail if so
         TDC             ; Clear A
         LDA $28         ; Cursor slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         CMP $E0         ; Slots are same?
         BNE C379F9      ; Swap chars if not

; Fork: Double-clicked a slot
C379C8:  LDA $E0         ; Chosen slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Empty slot?
         BMI C37A0B      ; Fail if so
         LDA #$42        ; C3/6966
         STA $27         ; Queue Status menu
         LDA #$67        ; C3/8184
         STA $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Fork: Swap slot contents
C379F9:  JSR C30F1D      ; Sound: Click
         LDA #$07        ; Actors: Delete
         TRB $47         ; Set menu flag
         JSR C37A8C      ; Swap positions
         JSR C3121B      ; Delete actors
         JSR C37DA7      ; Create actors
         BRA C37A1A      ; Next: Choice 1

; Fork: Double-clicked empty slot
C37A0B:  JSR C3C5C6      ; Buzzer + Mosaic

; Fork: Handle B
C37A11:  LDA $09         ; Pushing B?
         BPL C37A22      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C37A1A:  LDA #$2D        ; C3/78FC
         STA $26         ; Next: Choice 1
         LDA #$05        ; Blinker: Off
         TRB $46         ; Set menu flag
C37A22:  RTS

; Fork: Forced member
C37A23:  JMP C3C5C6      ; Buzzer + Mosaic

; Handle attempt to exit Lineup menu
C37A2A:  LDA $0201       ; Group count
;        AND #$7F        ; Clear flag
         ASL A           ; x2
         ASL A           ; x4 members
         STA $F3         ; Set index cap
         STZ $F4         ; Clear its HB
         TDC             ; Clear A
         TAX             ; Slot index: 0
C37A37:  STZ $E0         ; Members: 0
         LDY #$0004      ; Slots left: 4
C37A3C:  LDA $7E9D99,X   ; Empty slot?
         BMI C37A44      ; Branch if so
         INC $E0         ; +1 member
C37A44:  INX             ; Slot index +1
         DEY             ; One less slot
         BNE C37A3C      ; Loop till 4th
         LDA $E0         ; Empty party?
         BEQ C37A5F      ; Fail if so
         CPX $F3         ; Last party?
         BNE C37A37      ; Loop if not
;        STZ $0205       ; Never read...
         LDA #$FF        ; Null value
         STA $27         ; Queue menu exit
         LDA #$67        ; C3/8184
         STA $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Draw "You need <#> group(s)."
C37A5F:  JSR C30F2B      ; Play buzzer
         JSR C3D24D      ; Color: User's
         LDA $0201       ; Event data
         AND #$07        ; Group count
         DEC A           ; One group?
         BEQ C37A7D      ; Branch if so
         LDY #C38244     ; Text pointer
         JSR C30326      ; Draw message
         LDX #$392F      ; Tilemap pointer
         JSR C37D8B      ; Draw group count
         BRA C37A83      ; Skip 2 lines

; Fork: Draw "No one there!"
C37A7D:  LDY #C38258     ; Text pointer
         JSR C30326      ; Draw message
C37A83:  LDA #$20        ; Frames: 32
         STA $20         ; Set wait timer
         LDA #$69        ; C3/821B
         STA $26         ; Next: Wait
         RTS

; Swap actor positions in Lineup menu
C37A8C:  TDC             ; Clear A
         LDA $28         ; Chosen slot A
         CLC             ; Prepare ADC
         ADC $49         ; +16 if on party
         TAX             ; Index sum
         PHX             ; Memorize it
         LDA $7E9D89,X   ; Actor in slot A
         STA $E0         ; Memorize it
         LDA.L C37B43,X  ; Party position
         STA $E3         ; Memorize it

; Fork: Get actor data for slot B
C37AAB:  LDA $4B         ; Chosen slot B
         CLC             ; ...
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         PHX             ; Memorize it
         LDA $7E9D89,X   ; Actor in slot B
         STA $E1         ; Memorize it
         LDA.L C37B43,X  ; Party position
         STA $E2         ; Memorize it

; Fork: Update party info for both actors
C37AF5:  LDX #$0001      ; 1st: Actor B
.loop    LDA $E0,X       ; Actor in slot
         BMI .next       ; Skip if none
         TAY             ; Index it
         LDA $1850,Y     ; Actor info
         AND #$20        ; Isolate row
         ORA $E2,X       ; Add new position
         STA $1850,Y     ; Save changes
.next    DEX             ; Actor index -1
         BPL .loop       ; Loop till < 0

; Fork: Swap slot contents
C37B25:  PLX             ; Menu slot B
         LDA $E0         ; Actor in slot A
         JSR .recur      ; Put in slot B
         PLX             ; Menu slot A
         LDA $E1         ; Actor in slot B
.recur   STA $7E9D89,X   ; Put in slot A
         RTS

; Roster position and object status for Lineup menu slots
C37B43:  db $40          ; Non-party slot 1
         db $40          ; Non-party slot 2
         db $40          ; Non-party slot 3
         db $40          ; Non-party slot 4
         db $40          ; Non-party slot 5
         db $40          ; Non-party slot 6
         db $40          ; Non-party slot 7
         db $40          ; Non-party slot 8
         db $40          ; Non-party slot 9
         db $40          ; Non-party slot 10
         db $40          ; Non-party slot 11
         db $40          ; Non-party slot 12
         db $40          ; Non-party slot 13
         db $40          ; Non-party slot 14
         db $40          ; Non-party slot 15
         db $40          ; Non-party slot 16
         db $41          ; Party 1, NW
         db $49          ; Party 1, SW
         db $51          ; Party 1, NE
         db $59          ; Party 1, SE
         db $42          ; Party 2, NW
         db $4A          ; Party 2, SW
         db $52          ; Party 2, NE
         db $5A          ; Party 2, SE
         db $43          ; Party 3, NW
         db $4B          ; Party 3, SW
         db $53          ; Party 3, NE
         db $5B          ; Party 3, SE

; New cursor column upon entering 3-party area of Lineup menu
C37BFA:  db $00          ; 1 -> 1
         db $01          ; 2 -> 2
         db $01          ; 3 -> 2
         db $02          ; 4 -> 3
         db $03          ; 5 -> 4
         db $04          ; 6 -> 5
         db $04          ; 7 -> 5
         db $05          ; 8 -> 6

; New cursor column upon leaving 3-party area of Lineup menu
C37C0A:  db $00          ; 1 -> 1
         db $01          ; 2 -> 2
         db $03          ; 3 -> 4
         db $04          ; 4 -> 5
         db $06          ; 5 -> 7
         db $07          ; 6 -> 8

; Load nav data for party area of Lineup menu, relocate cursor
C37B6F:  LDA $4D         ; Cursor column
         STA $5E         ; Set as former
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C37B89      ; Branch if so
         DEC A           ; Two groups?
         BEQ C37B99      ; Branch if so

; Fork: Three groups
C37B80:  LDY #C37C99     ; C3/7C99
         JSR C30681      ; Load navig data
         TDC             ; Clear A
         LDA $5E         ; Former column
         TAX             ; Index it
         LDA.L C37BFA,X  ; Intended column
         STA $4D         ; Set new column
         JMP C37C4C      ; Relocate cursor

; Fork: One group
C37B89:  LDY #C37C77     ; C3/7C77
         JSR C30681      ; Load navig data
         LDA $5E         ; Old cursor column
         BEQ C37B94      ; Retain if first
         LDA #$01        ; Column: 2nd
C37B94:  STA $4D         ; Set new column
         BRA C37C2E      ; Relocate cursor

; Fork: Two groups
C37B99:  LDY #C37C84     ; C3/7C84
         JSR C30681      ; Load navig data
         LDA $5E         ; Old cursor column
         CMP #$03        ; Within first 3?
         BCC C37BA4      ; Retain it if so
         LDA #$03        ; Column: 4th
C37BA4:  STA $4D         ; Set new column
         BRA C37C3D      ; Relocate cursor

; Handle D-Pad for Lineup menu
C37BA9:  LDA $4A         ; In party area?
         BEQ C37C1C      ; Branch if not
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C37C2B      ; Branch if so
         DEC A           ; Two groups?
         BEQ C37C3A      ; Branch if so
         BRA C37C49      ; Handle D-Pad

; Load navigation data for non-party area of Lineup menu
C37C16:  LDY #C37C52     ; C3/7C52
         JMP C30681      ; Load navig data

; Handle D-Pad for non-party area of Lineup menu
C37C1C:  JSR C307B0      ; Handle D-Pad
C37C1F:  LDY #C37C57     ; C3/7C57
         JMP C306C3      ; Relocate cursor

; Handle D-Pad for single-party area of Lineup menu
C37C2B:  JSR C307B0      ; Handle D-Pad
C37C2E:  LDY #C37C7C     ; C3/7C7C
         JMP C306BA      ; Relocate cursor

; Handle D-Pad for two-party area of Lineup menu
C37C3A:  JSR C307B0      ; Handle D-Pad
C37C3D:  LDY #C37C89     ; C3/7C89
         JMP C306BA      ; Relocate cursor

; Handle D-Pad for three-party area of Lineup menu
C37C49:  JSR C307B0      ; Handle D-Pad
C37C4C:  LDY #C37C9E     ; C3/7C9E
         JMP C306BA      ; Relocate cursor

; Draw Lineup menu windows and uppermost text
C37CB6:  LDX #C37D2C     ; C3/7D2C
         JSR boxes       ; Draw main boxes
         JSR C37D06      ; Draw party boxes
         JSR C30EBD      ; Upload windows
         JSR C371D0      ; Clear BG3 map A
         JSR C30ED9      ; Upload BG3 A+B
         JSR C371A9      ; Clear BG1 map A
         JSR C3658A      ; Color: Blue
         LDY #C3823D     ; Text pointer
         JSR C30326      ; Draw "Lineup"
         JSR C37CF6      ; Draw "Form..."
         JMP C30E93      ; Upload BG1 A+B

; Draw "Form <#> group(s)."
C37CF6:  JSR C3D24D      ; Color: User's
         LDY #C38229     ; Text pointer
         JSR C30326      ; Draw "Form..."
         LDX #$3929      ; Tilemap pointer
         BRA C37D8B      ; Draw group count

; Draw extra party boxes for Lineup menu
C37D06:  TDC             ; Clear A
         LDA $0201       ; Group count
         AND #$7F        ; Clear flag
         DEC A           ; One group?
         BEQ C37D8A      ; Exit if so
         LDX #C37D48     ; C3/75B4
         DEC A           ; 2 parties?
         BEQ .draw       ; 1 box if so
         LDX #C37D44     ; C3/75B0
.draw    JMP boxes       ; Draw box(es)

; Update displayed actor info in Lineup menu
C37D4C:  LDA #$06        ; Status icons: Temp
         TSB $47         ; Set menu flag
         JSR C383B6      ; Queue face upload
         JSR C38435      ; Load face colors
         JMP C380E7      ; Draw actor info

; Set to condense text in Lineup menu
C37D59:  LDY #C37D78     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1v        ; Queue BG1 V-Pan
C37D8A:  RTS

; Draw number of required groups for Lineup menu
C37D8B:  LDA $0201       ; Event data
         AND #$07        ; Group count
         DEC A           ; Now 0-6
         JMP C341F7      ; Draw value

; List members and create actors after changes in Lineup menu
C37DA7:  LDX #$008F      ; Starting slot
         LDA #$FF        ; Actor: None
C37DAB:  STA $7E9D99,X   ; Clear slot
         DEX             ; Slot number -1
         BPL C37DAB      ; Loop till < 0
         JSR C37E7E      ; Compile members
         JSR C37FE7      ; Create members
         BRA C37E17      ; And candidates

; List and create actors in Lineup menu, define locked slots
C37DBE:  LDX #$009F      ; Starting slot
         LDA #$FF        ; Actor: None
C37DC2:  STA $7E9D89,X   ; Clear slot
         DEX             ; Slot number -1
         BPL C37DC2      ; Loop till < 0
         JSR wm9D89      ; WRAM: 7E/9D89
         LDA $0201       ; Forced members?
         BMI C37DF9      ; Branch if not

; Fork: Compile candidates, etc.
C37DD7:  LDX $00         ; 1st: Terra
C37DD9:  LDA $1850,X     ; Party info
         ASL A           ; Object's off?
         BPL C37DEB      ; Skip if so
         AND #$0E        ; In a party?
         BNE C37DEB      ; Skip if so
         TXA             ; Actor's slot
         STA $2180       ; Add to list
C37DEB:  INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C37DD9      ; Loop if not
         LDA #$FF        ; Null value
         STA $2180       ; End list
         BRA C37E0B      ; Make/lock chars

; Fork: Clear assigned party for all actors
C37DF9:  LDX #$000F      ; 1st: Guest 2
C37DFB:  LDA $1850,X     ; Party info
         AND #$F8        ; Clear party
         STA $1850,X     ; Save changes
         DEX             ; Actor slot -1
         BPL C37DFB      ; Loop till last
         BRA C37DD7      ; Create actors

; List members, create actors, and define locked slots in Lineup menu
C37E0B:  JSR C37E7E      ; Compile members
         JSR C37FE7      ; Create members
         JSR C37E17      ; And candidates
         JMP C380A0      ; Set locked slots

; Create all candidates in Lineup menu
C37E17:  LDX $00         ; Menu slot: 1
C37E19:  LDA $7E9D89,X   ; Actor in slot
         BMI C37E53      ; Skip if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C381F3     ; C3/81F3
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Save for arrow
         JSR C3807F      ; Set anim ptr
         PLX             ; Menu slot
         LDA.L C37E5E,X  ; X position
         STA $33CA,Y     ; Set sprite's
         LDA.L C37E6E,X  ; Y position
         STA $344A,Y     ; Set sprite's
C37E53:  INX             ; Menu slot +1
         CPX #$0010      ; Done top 16?
         BNE C37E19      ; Loop if not
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Compile party members for Lineup menu
C37E7E:  LDY #$000F      ; 1st: Guest 2
.loop    TDC             ; Clear A
         LDA $1850,Y     ; Party info
         PHA             ; Memorize it
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         STA $E0         ; Memorize it
         PLA             ; Party info
         ASL A           ; Object's off?
         BPL .next       ; Skip if so
         AND #$06        ; Isolate party
         BEQ .next       ; Skip if none
         ASL A           ; Party x4
         ORA $E0         ; Add roster slot
         TAX             ; Index sum
         TYA             ; Actor slot
         STA $7E9D99-4,X ; Add to list
.next    DEY             ; Actor slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Create all party members in Lineup menu
C37FE7:  LDX #$9D99      ; 7E/9D99
         STX $F3         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $F5         ; Set src HB
         LDX $00         ; Member slot: 1
C38015:  TXY             ; Member slot
         LDA [$F3],Y     ; Actor in slot
         BMI C38054      ; Skip if nobody
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C382C9     ; C3/82C9
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         PLA             ; Actor in slot
         STA $7E35C9,X   ; Put in queue
         JSR C3807F      ; Set anim ptr
         PLX             ; Menu slot
         LDA.L C38077,X  ; X position
         STA $33CA,Y     ; Set ally's
         PHX             ; Save X
         TDC             ; Clear A
         TXA             ; Menu slot
         AND #$03        ; Member slot
         TAX             ; Reindex it
         LDA.L C3807B,X  ; Y position
         STA $344A,Y     ; Set ally's
         PLX             ; Menu slot
C38054:  INX             ; Menu slot +1
         CPX #$000C      ; Done all 12?
         BNE C38015      ; Loop if not
         RTS

; Load pointer to actor's animation table
C3807F:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $01,X       ; Sprite set
C3808E:  ASL A           ; Double it
         TAX             ; Index it
         JSR db7e        ; Set DB to 7E
         REP #$20        ; 16-bit A
         LDA $D8E9A1,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         SEP #$20        ; 8-bit A
         LDA #$D8        ; Bank: D8
         STA $35CA,Y     ; Set ptr HB
         RTS

; Establish locked actor slots in Lineup menu
C380A0:  LDX #$002B      ; Menu slot: Last
C380A8:  PHX             ; Save menu slot
         TDC             ; Clear A
         LDA $7E9D89,X   ; Actor in slot
         BMI C380C7      ; Unlock if none
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3A456,X  ; Actor slot bit
         AND $0202       ; Forced member?
         SEP #$20        ; 8-bit A
         BEQ C380C7      ; Unlock if not
         LDA #$FF        ; Slot: Locked
         BRA C380C8      ; Skip a line
C380C7:  TDC             ; Slot: Unlocked
C380C8:  PLX             ; Current slot
         STA $7EAC8D,X   ; Set slot status
         DEX             ; Menu slot -1
         BPL C380A8      ; Loop till < 0
C380D2:  RTS

; Initialize and load portrait for Lineup menu
C380D3:  STZ $28         ; Portr slot: 1
         JSR C3826C      ; Init object
         LDY #$2F1A      ; Pos: 26, 47
         JSR objpos      ; Set sprite's
         JSR C31517      ; Upload graphics
         JSR C383B6      ; Queue updating
         JMP C38435      ; Load palette

; Draw actor info in Lineup menu
C380E7:  LDX #$3A09      ; Tilemap ptr
         LDY #$0180      ; Tiles: 192
         JSR clr_ram     ; Erase BG1 text
;        TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if in party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C380D2      ; Exit if nobody
         STA $C9         ; Memorize it
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor's address
         STA $67         ; Memorize it
         SEP #$20        ; 8-bit A
         JSR C3658A      ; Color: Blue
         LDX #C3815D     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3712C      ; Draw "LV/HP/MP"
         LDY #$3A1B      ; Class/KO pos
         LDX #$3048      ; Icon position
         LDA #$01        ; Anim mode: 1
         STA $48         ; Set for icons
         JSR C334C2      ; Do class/status
         LDY #$3A9B      ; Text position
         JSR C3356A      ; Draw actor name
         LDY #$3B1B      ; Text position
         JSR C335AE      ; Draw held esper
         LDY #C38172     ; Text pointer
         JSR C302F9      ; Draw HP's "/"
         LDY #C38176     ; Text pointer
         JSR C302F9      ; Draw MP's "/"
         LDX #C3817A     ; Coords tbl ptr
         JMP C30CD7      ; Draw LV, HP, MP

; 67: Queue fade-out for Lineup menu
C38184:  JSR C330EA      ; Queue fade-out
         BRA C38196      ; Skip a line

; 66: Queue fade-in for Lineup menu
C38193:  JSR C330F1      ; Queue fade-in
C38196:  LDY #$0008      ; Frames: 8
         STY $20         ; Set fade timer
         LDA #$68        ; C3/81A2
         STA $26         ; Next: Wait
         BRA C381AA      ; Update char info

; 68: Wait while Lineup menu fades in or out
C381A2:  LDY $20         ; Timer expired?
         BNE C381AA      ; Branch if not
         LDA $27         ; Queued command
         STA $26         ; Execute it next
C381AA:  JMP C37D4C      ; Update char info

; Update arrow for gear data menu
C381AD:  BNE C381D2      ; If mode 1

; Mode 0: Initialize arrow
C381B5:  LDA #$D8        ; Anim ptr HB
         LDY #$ECF9      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C381D2:  TXY             ; Queue index
         LDX $00         ; Arrow: Blank
         LDA $99         ; Arrow status
         BEQ C381DF      ; Hide if bogus
         BMI C38219      ; Delete if off
         INX #2          ; Arrow: Normal
C381DF:  REP #$20        ; 16-bit A
         LDA $D8ECF5,X   ; Anim table ptr
         STA $32C9,Y     ; Set sprite's
         JMP oamsec      ; Set OAM; requeue

; Update Lineup or Colosseum candidate, or enemy Shadow
C381F3:  BNE C3820C      ; If mode 1

; Mode 0: Initialize sprite
C381FB:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         JSR C3127_      ; Set pose timer
         INC $3649,X     ; Mode +1
;        JSR C38335      ; No arrow...

; Mode 1: Sustain sprite
C3820C:  LDA $47         ; Menu flags
         LSR A           ; Remove actors?
         BCC C38219      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C38219:  CLC             ; Set to dequeue
         RTS

; 69: Erase warning in Lineup menu after delay
C3821B:  LDA $20         ; Delay expired?
         BNE C38226      ; Branch if not
         LDA #$2D        ; C3/78FC
         STA $26         ; Next: Choice 1
         JSR C37CF6      ; Draw "Form..."
C38226:  JMP C37D4C      ; Update char info

; Create portrait for Lineup menu
C3826C:  JSR C36823      ; Queue OAM fn
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         LDA $28         ; Portrait slot
         ASL A           ; Double it
         JSR C30B3_      ; Load anim ptr
         PLB             ; Restore DB
C38294:  RTS

; Sort members by actual order rather than actor slot
C382AC:  TDC             ; Clear A
         LDA $7E9D89,X   ; Actor slot
         STA $E1         ; Memorize it
         BMI C38294      ; Exit if none
         PHX             ; List slot
         TAX             ; Actor slot
         LDA $1850,X     ; Party info
         AND #$18        ; Roster slot
         LSR A           ; Put in b2-b3
         LSR A           ; Put in b1-b2
         LSR A           ; Now 0-3
         TAY             ; Index it
         LDA $E1         ; Actor slot
         STA [$E7],Y     ; To new list
         PLX             ; List slot
         INX             ; List slot +1
         BRA C382AC      ; Do next slot

; Update conditional actor-related sprite
C382C9:  TAX             ; Index mode
         JMP (C382CD,X)  ; Handle mode

; Jump table for the above
C382CD:  dw C382D9       ; Initialize sprite V1
         dw C382ED       ; Initialize sprite V2
         dw C38305       ; Sustain sprite V1
         dw C38314       ; Sustain sprite V2

; Mode 0: Init Lineup member, non-Lineup status icon, or arrow under actor; create arrow under forced member
C382D9:  LDA #$01        ; Ax like OBJs: N
         TSB $47         ; Set menu flag
         JSR C3127_      ; Set pose timer
         LDA #$02        ; Mode: 2
         STA $3649,X     ; Set sprite's
         TDC             ; Lineup member: Y
         JSR C38335      ; Add Lineup arrow

; Mode 3: Sustain Lineup member, non-Lineup status icon, or arrow under actor
C38305:  LDA $47         ; Menu flags
         LSR A           ; Ax like objects?
         BCS C38321      ; Branch if not
C38312:  CLC             ; Set to dequeue
         RTS

; Mode 1: Init Colosseum challenger or Lineup status icon
C382ED:  JSR C3127_      ; Set pose timer
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set sprite's

; Mode 4: Sustain Colosseum challenger or Lineup status icon
C38314:  LDA $47         ; Menu flags
         AND #$02        ; Temp sprite?
         BEQ C38321      ; Branch if not
         JSR C3128C      ; Define OAM
         CLC             ; Set to dequeue
C38320:  RTS             ; Exit
C38321:  JMP oamsec      ; Set OAM; requeue

; Create large arrow under actor if forced into party
C38335:  STA $E6         ; Save pose timer
         LDA $0200       ; Menu number
         CMP #$04        ; Lineup menu?
         BNE C38320      ; Exit if not
         LDX $2D         ; Queue index
         TDC             ; Clear A
         LDA $35C9,X     ; Actor in slot
         BMI C38320      ; Exit if arrow
         ASL A           ; Double it
         REP #$20        ; 16-bit A
         TAX             ; Index it
         LDA.L C3A456,X  ; Actor slot bit
         AND $0202       ; Forced member?
         SEP #$20        ; 8-bit A
         BEQ C38320      ; Exit if not
         PHB             ; Save DB
         LDY #C381F3     ; C3/81F3
         LDA $E6         ; Party member?
         BNE C38369      ; Branch if not
         LDY #C382C9     ; C3/82C9
C38369:  JSR qanim3      ; Queue OAM fn
         LDA #$D8        ; Anim ptr HB
         LDY #$EC33      ; Anim ptr LBs
         JSR anm_st      ; Set arrow's
         PLB             ; Restore DB
         LDA #$FF        ; Actor: None
         STA $35C9,X     ; For C3/8344
         LDY $374A,X     ; Actor's index
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         STA $344A,X     ; Set arrow's
         RTS

; Set to upload portrait for Lineup menu
C383B6:  LDY #$2600      ; $2600
         STY $1B         ; Set VRAM ptr
         LDY #$0320      ; Bytes: 800
         STY $19         ; Set data size
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BMI C3842B      ; Blank if none
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor address
         TAY             ; Index it
         JSR faceptr     ; GFX pointer
;        CLC             ; Prepare ADC
         ADC #$1D00      ; Add base adr
         STA $1D         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$ED        ; Bank: ED
         STA $1F         ; Set src HB
         RTS

; Fork: Point to blank portrait
C3842B:  LDY #$9F51      ; 7E/9F51
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Load portrait palette for Lineup menu
C38435:  LDY $00         ; Palette: 0
         PHY             ; Save dest
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         CLC             ; Prepare ADC
         ADC $4A         ; +16 if on party
         TAX             ; Index sum
         LDA $7E9D89,X   ; Actor in slot
         BPL C3845D      ; Branch if any
         TDC             ; Use Terra
C3845D:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA #$10        ; Colors: 16
         STA $E3         ; Set counter
         LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C38478      ; Branch if not
         LDA #$0F        ; Use Imp data
         BRA C3847B      ; Skip a line
C38478:  LDA $0001,Y     ; Graphics set
C3847B:  TAX             ; Index it
         LDA.L C37694,X  ; Palette number
         JSR x32r        ; x32
         TAX             ; Index it
         PLY             ; RAM index
         JMP C36ECC      ; Load palette

; Load navigation data for Item, Colosseum, or Sell menu
C384A3:  LDY #C384B2     ; C3/84B2
         JMP C30681      ; Load navig data

; Handle D-Pad for Item, Colosseum, or Sell menu
C384A9:  JSR C38948      ; Handle D-Pad
C384AC:  LDY #C384B7     ; C3/84B7
         JMP C306CB      ; Relocate cursor

; Handle D-Pad for rare item menu
C384E5:  JSR C307B0      ; Handle D-Pad
C384E8:  LDY #C384F3     ; C3/84F3
         JMP C306C3      ; Relocate cursor

; Load navigation data for Item menu options
C3852F:  LDY #C38547     ; C3/8547
         JMP C30681      ; Load navig data

; Relocate cursor for Item menu options
C38535:  LDY #C3854C     ; C3/854C
         JMP C306C3      ; Relocate cursor

; Handle D-Pad for Item menu options
C3853B:  JSR C307B0      ; Handle D-Pad
         JSR C38535      ; Relocate cursor
         LDY $4D         ; Cursor position
         STY $0234       ; To cursor memory
         RTS

; Draw Item menu with inventory; upload element graphics
C38552:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C385C2     ; C3/85C2
         JSR boxes_      ; Upload windows
         JSR bg3d_cl     ; Clear BG3 maps
         JSR C3D252      ; Color: Blue
         LDY #C394A0     ; Text pointer
         JSR C30326      ; Draw "Item"
         JSR C3D24D      ; Color: User's
         LDX #C3949A     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3714E      ; Draw options
         JSR C3B080      ; Build desc map
         JSR C3B319      ; Upload elements
         JSR C371AD      ; Clear BG1 map B
         JSR C385BC      ; Draw inventory
         JSR C38A72      ; Desc; item count
         JMP up_txt      ; Upload text

; Draw inventory after clearing tilemap (Item, Colosseum, Sell)
C385BC:  JSR C371A9      ; Clear BG1 map A
         JMP C38737      ; Draw inventory

; Set to condense text in Item, Colosseum, or Sell menu
C385DA:  LDY #C38706     ; C3/8706
         JSR bg3v_       ; Queue BG3 V-Pan
         JSR C38644      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C385FD:  LDA.L C38689,X  ; BG1 H-Pan data
         STA $7E9A09,X   ; Save in RAM
         DEX             ; Index -1
         BPL C385FD      ; Loop till < 0
         LDY #$9A09      ; Src: 7E/9A09
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load BG1 vertical shift table for Item, Colosseum, or Sell menu
C38644:  LDX $00         ; Index: 0
C38646:  LDA.L C38696,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At items?
         BNE C38646      ; Loop if not
C38654:  LDA.L C38696,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; Top BG1 row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C38696,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$006C      ; Beyond items?
         BNE C38654      ; Loop if not
C3867A:  LDA.L C38696,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0070      ; End of table?
         BNE C3867A      ; Loop if not
         RTS

; Draw inventory for Item, Colosseum, or Sell menu
C38737:  JSR C38B78      ; Define $E5, $E6
         LDA #$0A        ; Rows left: 10
C3873D:  PHA             ; Save counter
         JSR C38752      ; Draw item row
         INC $E5         ; Item slot +1
         INC $E5         ; Item slot +1
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C3873D      ; Loop till last
         RTS

; Draw a row of two items for Item, Colosseum, or Sell menu
C38752:  TDC             ; Clear A
         LDA $E5         ; Item slot A
         TAY             ; Index it
         PHY             ; Push on stack
         PHY             ; Push on stack
         PHY             ; Push on stack
         JSR C387C6      ; Choose palette
         LDA $1969,Y     ; Item quantity
         JSR C30563      ; Turn into text
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$000D      ; X: 13
         JSR C38820      ; Compute map ptr
         JSR C30539      ; Draw quantity
         LDA $E6         ; BG1 write row
         LDX #$0003      ; X: 3
         JSR C38820      ; Compute map ptr
         PLY             ; Item slot A
         JSR C3883A      ; Load "<item>:"
         JSR C387B_      ; Draw item A

; Fork: Handle item B
C38786:  PLY             ; Item slot A
         INY             ; Now slot B
         JSR C387C6      ; Choose palette
         LDA $1969,Y     ; Item quantity
         JSR C30563      ; Turn into text
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$001B      ; X: 27
         JSR C38820      ; Compute map ptr
         JSR C30539      ; Draw quantity
         LDA $E6         ; BG1 write row
         LDX #$0011      ; X: 17
         JSR C38820      ; Compute map ptr
         PLY             ; Item slot A
         INY             ; Now slot B
         JSR C3883A      ; Load "<item>:"

; Draw memorized string with diacritics
C387B_:  STZ $2180       ; End string
C387B9:  LDY #$9E89      ; Source LBs
         LDA #$7E        ; Source HB
         JMP C3032A      ; Draw string

; Choose item's color for Item, Colosseum, or Sell menu
C387C6:  LDA $0200       ; Root menu
         CMP #$03        ; Shop menu?
         BEQ C38806      ; Enable if so
         CMP #$07        ; Colosseum?
         BEQ C38806      ; Enable if so

; Fork: Main menu
C387D7:  LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C38806      ; Enable if so
         CMP #$F7        ; Tent?
         BEQ C38810      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C38810      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C38817      ; Branch if so
         JSR itm_cl1     ; Item class
         CMP #$06        ; Consumable?
         BNE C3880B      ; Disable if not
         LDA $D85000,X   ; Properties
         ASL A           ; Usable in field?
         BPL C3880B      ; Disable if not
C38806:  JMP C3D24D      ; Color: User's

; Fork: Tent or Sleeping Bag
C38810:  LDA $0201       ; Can save here?
         BMI C38806      ; Enable if so

; Fork: Set color to gray
C3880B:  LDA #$28        ; Palette 2
         STA $29         ; Color: Gray
         RTS

; Fork: Warp Stone
C38817:  LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BNE C38806      ; Enable if so
         BRA C3880B      ; Color: Gray

; Compute position into BG1 tilemap A
C38820:  PHA             ; Save Y pos
         TDC             ; Clear A
         PLA             ; Y position
         JSR x64         ; x64
         STA $E7         ; Memorize it
         TXA             ; X position
         ASL A           ; Double it
         CLC             ; Prepare ADC
         ADC $E7         ; Add Y x64
         ADC #$3849      ; Add base adr
         STA $7E9E89     ; Set position
         TAX             ; Copy it to X
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         RTS

; Load owned item's name, add colon (Item, Colosseum, Sell)
C3883A:  JSR wm9E8B      ; WRAM: 7E/9E8B
         LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ C38877      ; Blank if so
C3884F:  JSR C3CFC_      ; Load name
         LDA.B #!coln    ; Char: ":"
         STA $2180       ; Add to string
C38876:  RTS

; Fork: Blank item name, colon, and quantity
C38877:  LDY.W #!itm_ns+3; Spaces: 12
         JMP spaces      ; Add to string

; Adjust BG1 vertical shift amounts while list scrolls
C38886:  LDX #$0012      ; Scanline: 88th
C38889:  SEP #$20        ; 8-bit A
         LDA $7E9849,X   ; Scanline amount
         CMP #$1E        ; Last 30 lines?
         BEQ C38876      ; Exit if so
         INX             ; RAM index +1
         PHX             ; Memorize it
         TDC             ; Clear A
         LDA $20         ; Scroll timer
         REP #$21        ; 16-bit A; C-
         LDY $41         ; Scrolling up?
         BPL C388A4      ; Branch if not
         ADC #$0003      ; Timer +3
C388A4:  ASL A           ; Timer x2
         TAX             ; Index it
         TAY             ; Memorize it
         LDA.L C388E0,X  ; Shift mod; R1/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C388EC,X  ; Shift mod; R2/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         INX             ; RAM index +1
         PHX             ; Memorize it
         TYX             ; ROM index
         LDA.L C388F8,X  ; Shift mod; R3/3
         PLX             ; RAM index
         CLC             ; Prepare ADC
         ADC $7E9849,X   ; Add actual shift
         STA $7E9849,X   ; Set actual shift
         INX             ; RAM index +1
         INX             ; RAM index +1
         BRA C38889      ; Do next 12 lines

; Update scroll parameters for list
C38904:  TAX             ; Index mode
         JMP (C38908,X)  ; Handle mode

; Jump table for the above
C38908:  dw C38910       ; Scroll upward
         dw C3891D       ; Scroll downward
         dw C38928       ; Set timer
         dw C38931       ; Check timer

; Mode 0: Scroll upward
C38910:  REP #$20        ; 16-bit A
         LDA #$FFFC      ; 4 px up
         STA $41         ; Set V-Speed
         BRA C38928      ; Init timer

; Mode 1: Scroll downward
C3891D:  REP #$20        ; 16-bit A
         LDA #$0004      ; 4 px down
         STA $41         ; Set V-Speed

; Mode 2: Set timer
C38928:  SEP #$20        ; 8-bit A
         LDX $2D         ; Queue index
         LDA #$03        ; Mode: 3
         STA $3649,X     ; Set next mode
         STA $20         ; Set timer

; Mode 3: Check timer
C38931:  LDA $20         ; Timer expired?
         BEQ C3893D      ; Stop if so
         LDA #$20        ; Scroll BG1: Y
         TSB $46         ; Set menu flag
         SEC             ; Set to requeue
         RTS

; Fork: Stop scrolling
C3893D:  LDY $00         ; Clear Y
         STY $41         ; BG1 V-Speed: 0
         LDA #$20        ; Scroll BG1: N
         TRB $46         ; Set menu flag
         CLC             ; Set to dequeue
C38947:  RTS

; Handle D-Pad for scrollable list, change row when wrapping
C38948:  LDA $20         ; Scrolling now?
         BNE C38947      ; Exit if so

; Fork: Handle up
C3894C:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3896B      ; Branch if not
         LDA $4E         ; On first row?
         BNE C38963      ; Go up if not
         LDA $4A         ; At top of list?
         BEQ C38947      ; Exit if so
         DEC $50         ; List row -1
         JSR C38A07      ; Queue scrolling
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor up
C38963:  DEC $50         ; List row -1
         DEC $4E         ; Cursor row -1
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle down
C3896B:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C38991      ; Branch if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BNE C3898A      ; Go down if not
         LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C38947      ; Exit if so
         INC $50         ; List row +1
         JSR C38A1F      ; Queue scrolling
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor down
C3898A:  INC $50         ; List row +1
         INC $4E         ; Cursor row +1
         JSR C30F0E      ; Sound: Cursor

; Fork: Handle left
C38991:  LDA $0B         ; Semi-auto keys
         BIT #$02        ; Pushing left?
         BEQ C389CA      ; Branch if not
         LDA $4D         ; On first column?
         BNE C389C2      ; Branch if not
         LDA $4E         ; On top row?
         BEQ C389AE      ; Branch if so
         DEC $4E         ; Cursor row -1
         DEC $50         ; List row -1
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         JMP C30F0E      ; Sound: Cursor

; Fork: Wrap to upper, offscreen row
C389AE:  LDA $4A         ; At top of list?
         BEQ C38947      ; Exit if so
         JSR C38A07      ; Queue scrolling
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         STA $4D         ; Set as cursor's
         STA $4F         ; Set as list's
         DEC $50         ; List row -1
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor left
C389C2:  DEC $4D         ; Cursor column -1
         DEC $4F         ; List column -1
         JMP C30F0E      ; Sound: Cursor

; Fork: Handle right
C389CA:  LSR A           ; Pushing right?
         BCC C38A1E      ; Exit if not
         LDA $53         ; Furthest column
         DEC A           ; Adjust value
         CMP $4D         ; Cursor's there?
         BNE C389FF      ; Go right if not
         LDA $54         ; Bottom menu row
         DEC A           ; Adjust value
         CMP $4E         ; Cursor's there?
         BEQ C389EB      ; Branch if so
         STZ $4D         ; Cursor column: 1
         STZ $4F         ; List column: 1
         INC $4E         ; Cursor row +1
         INC $50         ; List row +1
         JMP C30F0E      ; Sound: Cursor

; Fork: Wrap to lower, offscreen row
C389EB:  LDA $4A         ; Scroll position
         CMP $5C         ; At very bottom?
         BEQ C38A1E      ; Exit if so
         JSR C38A1F      ; Queue scrolling
         STZ $4D         ; Cursor column: 1
         STZ $4F         ; List column: 1
         INC $50         ; List row +1
         JMP C30F0E      ; Sound: Cursor

; Fork: Move cursor right
C389FF:  INC $4D         ; Cursor column +1
         INC $4F         ; List column +1
         JMP C30F0E      ; Sound: Cursor

; Set to scroll list upward, draw row to scroll into view
C38A07:  DEC $4A         ; Scroll pos -1
         DEC $49         ; Top BG1 row -1
         JSR C38B78      ; Define $E5, $E6
         JSR C38A5E      ; Draw new row
         LDY #C38904     ; C3/8904
         JSR qanim0      ; Queue scroll fn
         TDC             ; Anim mode: Up
         STA $7E3649,X   ; Set scroll mode
C38A1E:  RTS

; Set to scroll list downward, draw row to scroll into view
C38A1F:  LDA $5B         ; Column count
         XBA             ; Put in B
         LDA $5A         ; Rows per page
         CLC             ; Prepare ADC
         ADC $4A         ; Add scroll pos
         JSR mul8        ; Sum x count
         STA $E5         ; Set SW list slot
         LDA $49         ; Top BG1 write row
;        CLC             ; Prepare ADC
         ADC $5A         ; Get bottom row +1
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
         INC $4A         ; Scroll pos +1
         INC $49         ; Top BG1 row +1
         JSR C38A5E      ; Draw new row
         LDY #C38904     ; C3/8904
         JSR qanim0      ; Queue scroll fn
         LDA #$01        ; Anim mode: Down
         STA $7E3649,X   ; Set scroll mode
         RTS

; Draw list elements to scroll into view
C38A5E:  TDC             ; Clear A
         LDA $2A         ; List type
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C38A66,X)  ; Draw row

; Jump table for the above
C38A66:  dw C38752       ; Inventory
         dw C35670       ; Magic
         dw C35925       ; Lore
         dw C35A49       ; Rage
         dw C35B3D       ; Esper
         dw C3A4D1       ; Gear

; Load common item's description and draw item count in Item menu
C38A72:  JSR C38A89      ; Set desc ptrs
         JSR C3CF26      ; Selected item
         JSR C35D95      ; Load description
         JSR C38AD7      ; Count items
         JSR C3D24D      ; Color: User's
         BRA C38AFB      ; Draw item count

; Prepare item description loading
C38A89:  LDX.W #!itm_dp  ; D8/6E00
         STX $E7         ; Set ptr loc LBs
         LDX.W #!itm_dl  ; ED/6400
         STX $EB         ; Set text loc LBs
         LDA.B #!itm_dp!h; Bank: D8
         STA $E9         ; Set ptr loc HB
         LDA.B #!itm_dl!h; Bank: ED
         STA $ED         ; Set text loc HB
wm9EC9:  LDX #$9EC9      ; 7E/9EC9
         STX $2181       ; Set WRAM LBs
         RTS

; Compute item data index
C38AA2:  XBA             ; Put item in B
         LDA #$1E        ; Item data size
         JSR mul8        ; Item x size
         TAX             ; Index product
         TDC             ; Clear A
         RTS

; Load rare item's description and draw item count
C38ABA:  LDX.W #!rar_d_p ; CE/FB60
         STX $E7         ; Set ptr loc LBs
         LDX.W #!rar_d_l ; CE/FC90
         STX $EB         ; Set text loc LBs
         LDA.B #!rar_d_h ; Bank: CE
         STA $E9         ; Set ptr loc HB
         STA $ED         ; Set text loc HB
         JSR C35D87      ; Load description
         JSR C38AEC      ; Count items
         JSR C3D24D      ; Color: User's
         BRA C38AFB      ; Draw item count

; Count number of common items
C38AD7:  LDX #$00FF      ; Item slot: 256
         STZ $64         ; Item count: 0
C38ADA:  LDA $1869,X     ; Item in slot
         INC A           ; None?
         BEQ C38AE2      ; Exclude if so
         INC $64         ; Item count +1
C38AE2:  DEX             ; Item slot -1
         BPL C38ADA      ; Loop till < 0
         RTS

; Count number of rare items
C38AEC:  TDC             ; Clear A
         TAX             ; Item slot: 1
C38AEE:  LDA $7E9D89,X   ; Empty slot?
         BMI C38AF7      ; Branch if so
         INX             ; Item slot +1
         BRA C38AEE      ; Check next slot
C38AF7:  TXA             ; Current slot
         STA $64         ; Set item count
         RTS

; Draw number of common or rare items
C38AFB:  LDA $64         ; Item count
         JSR C30563      ; Turn into text
         LDX #$7ABF      ; Text position
         JMP C30543      ; Draw 3 digits

; Blank item count in corner of Item menu
C38B06:  LDY #C395BF     ; Text pointer
         JMP C302F9      ; Draw 3 spaces

; Build and draw rare item list
C38B0C:  JSR C371A9      ; Clear BG1 map A
         JSR C38B15      ; Build item list
         BRA C38B5F      ; Draw item list

; Build rare item list
C38B15:  JSR wm9D89      ; WRAM: 7E/9D89
         LDY #$0021      ; Items: 33
         LDA #$FF        ; Empty item
C38B20:  STA $2180       ; Add to list
         DEY             ; One less left
         BNE C38B20      ; Loop till last
         JSR wm9D89      ; WRAM: 7E/9D89
         LDX $1EBA       ; Item packs A+B
         STX $EF         ; Memorize them
         LDA $1EBC       ; Item pack C
         STA $F1         ; Memorize it
         LDA $1EBD       ; Item pack D
         AND #$3F        ; Clear flags
         STA $F2         ; Memorize it
         TDC             ; Item: Cider
         STA $E0         ; Set as current
         TAX             ; Pack index: 0
         LDA #$04        ; Item packs: 4
         STA $E1         ; Set counter
C38B45:  LDY #$0008      ; Items left: 8
         LDA $EF,X       ; 8 owned items
C38B4A:  ROR A           ; Got current?
         PHA             ; Save item pack
         BCC C38B53      ; Skip if not
         LDA $E0         ; Item number
         STA $2180       ; Add to list
C38B53:  INC $E0         ; Item number +1
         PLA             ; 8 owned items
         DEY             ; One less item
         BNE C38B4A      ; Loop till last
         INX             ; Pack index +1
         DEC $E1         ; One less pack
         BNE C38B45      ; Loop till last
         RTS

; Draw rare item list
C38B5F:  JSR C38B78      ; Define $E6
         STZ $E5         ; Item slot: 1
         LDA #$0A        ; Rows left: 10
C38B67:  PHA             ; Save counter
         JSR C38B9C      ; Draw 3 items
         JSR e6add2      ; BG1 WR row +2
         PLA             ; Rows left
         DEC A           ; One less left
         BNE C38B67      ; Loop till last
         RTS

; Define BG1 row for drawing list, plus first onscreen list slot
C38B78:  LDA $49         ; Top BG1 write row
         ASL A           ; x2 for blank rows
         AND #$1F        ; Stay in limits
         STA $E6         ; Set BG1 write row
         LDA $4A         ; Scroll position
         XBA             ; Put it in B
         LDA $5B         ; Number of columns
         JSR mul8        ; Multiply them
         STA $E5         ; Set list slot
         TDC             ; Clear A
         RTS

; Draw a row of three rare items
C38B9C:  JSR C3D24D      ; Color: User's
         LDX #$0003      ; X: 3
         JSR .recur      ; Draw item A
         LDX #$000C      ; X: 12
         JSR .recur      ; Draw item B
         LDX #$0015      ; X: 21
.recur   JSR C38BC2      ; Define source
         JSR C38BD1      ; Draw item C
         INC $E5         ; Item slot +1
         RTS

; Set source for loading rare item name
C38BC2:  LDY.W #!rar_ns  ; Letters: 8
         STY $EB         ; Set src size
         LDY.W #!rar_np  ; CE/FBA0
         STY $EF         ; Set src LBs
         LDA.B #!rar_np!h; Bank: CE
         STA $F1         ; Set src HB
         RTS

; Draw rare item name
C38BD1:  LDA $E6         ; BG1 write row
         JSR C38820      ; Compute map ptr
         JSR C357BB      ; Item in slot
         BEQ C38C21      ; Exit if none
         JSR C38BF2      ; Load name
         JMP C387B_      ; Draw name

; Load fixed-size string from table
C38BF2:  JSR wm9E8B      ; WRAM: 7E/9E8B
         XBA             ; String number
         LDX $EB         ; String size
         TXA             ; Put in A
         JSR mul8        ; Number x size
         TAY             ; Index product
.loop    LDA [$EF],Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE .loop       ; Loop till last
C38C21:  RTS

; Handle double-clicked item
C38C22:  JSR C393B5      ; Selected item
         CMP #$FF        ; Empty slot?
         BEQ C38C9B      ; Fail if so
         JSR itm_cl1     ; Item class
         CMP #$06        ; Consumable?
         BNE C38CA0      ; Branch if not
         LDA $D85000,X   ; Item properties
         ASL A           ; Usable in field?
         BPL C38C9B      ; Fail if not
         JSR C393B5      ; Selected item
         CMP #$F7        ; Tent?
         BEQ C38C83      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BEQ C38C6D      ; Branch if so
         CMP #$FD        ; Warp Stone?
         BEQ C38C76      ; Branch if so
C38C5E:  LDY $4F         ; Cursor position
         STY $8E         ; Set return loc
         LDA $4A         ; Scroll position
         STA $90         ; Set return loc
         LDA #$6F        ; C3/920E
         STA $27         ; Queue usage menu
         STZ $26         ; Next: Fade-out
         RTS

; Fork: Sleeping Bag
C38C6D:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38C9B      ; Fail if not
         BRA C38C5E      ; Queue usage menu

; Fork: Warp Stone
C38C76:  STA $E6         ; Memorize item
         LDA $0201       ; Area permissions
         BIT #$02        ; Can warp here?
         BEQ C38C9B      ; Fail if not
         LDA #$03        ; Event: Warp
         BRA C38C8C      ; Destroy item

; Fork: Tent
C38C83:  STA $E6         ; Memorize item
         LDA $0201       ; Can save here?
         BPL C38C9B      ; Fail if not
         LDA #$02        ; Event: Tent
C38C8C:  STA $0205       ; Set aftereffect
         LDA $E6         ; Item
         JSR C3A5A5      ; Destroy it
         JMP fdexit      ; Queue menu exit

; Fork: Unusable consumable
C38C9B:  LDA #$08        ; C3/1F5D
         STA $26         ; Next: Choice 1
         RTS

; Fork: Compile gear's compatible actors
C38CA0:  JSR wm9D89      ; WRAM: 7E/9D89
         ASL A           ; Tool class?
         BEQ C38C9B      ; Abort if so
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         LDX $00         ; Current: Terra
C38CB4:  LSR A           ; Actor can use?
         BCC C38CC2      ; Skip if not
         SEP #$20        ; 8-bit A
         PHA             ; Save compat.
         TXA             ; Current actor
         STA $2180       ; Add to list
         PLA             ; Compatibility
C38CC2:  REP #$20        ; 16-bit A
         INX             ; Actor number +1
         CPX #$000E      ; Done all 14?
         BNE C38CB4      ; Loop if not
         SEP #$20        ; 8-bit A
         LDA #$FF        ; Terminator
         STA $2180       ; End list

; Fork: Initialize gear data menu
C38CD5:  REP #$20        ; 16-bit A
         LDA #$00E0      ; BG1 H-Shift: 224
         STA $7E9A10     ; Hide item list
         LDA #$7D4F      ; Tilemap ptr
         STA $7E9E89     ; Set item pos
         SEP #$20        ; 8-bit A
         LDA #$04        ; Cursor: Blank
         TRB $45         ; Set menu flag
         JSR C38D17      ; Stop desc/bar
         JSR C38D20      ; Create arrow
         JSR C3CF26      ; Selected item
         JSR C3CFC3      ; Load name
         JSR C38D38      ; Add "can be..."
         JSR C3D252      ; Color: Blue
         JSR C387B9      ; Draw string
         JSR C3D24D      ; Color: User's
         JSR C38D60      ; Draw actor list
         JSR C38DFB      ; Draw other info
         LDA #$64        ; C3/910D
         STA $26         ; Next: Sustain menu
         JSR C30F90      ; Queue text upload
         JMP C30FF4      ; Dequeue desc DMA

; Disable scrollbar and freeze description
C38D17:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         RTS

; Add " can be used by:" after item name
C38D38:  LDX #$0001      ; Skip item icon
C38D3B:  LDA $7E9E8B,X   ; Item letter
         CMP #$FF        ; Terminator?
         BEQ C38D43      ; Branch if so
         INX             ; RAM index +1
         CPX.W #!itm_ns  ; Done 8 chars?
         BNE C38D3B      ; Loop if not
C38D43:  LDY $00         ; ROM index: 0
C38D45:  PHX             ; Save RAM index
         TYX             ; ROM index
         LDA.L C394BD,X  ; Message letter
         PLX             ; RAM index
         STA $7E9E8B,X   ; Add to string
         INX             ; RAM index +1
         INY             ; ROM index +1
         CPY #$000F      ; Done 15 chars?
         BNE C38D45      ; Loop if not
         RTS

; Filter and draw gear's list of compatible actors
C38D60:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; List slot: 1
C38D68:  LDA $7E9D89,X   ; Eligible actor
         BMI C38DAE      ; Branch if end
         STA $E5         ; Memorize actor
         LDY $00         ; Actor slot: 1
         STY $E7         ; Save actor slot

; Fork: Exclude if never recruited or dead Shadow
C38D74:  STX $F3         ; Save list slot
         LDA $E5         ; Eligible actor
         CMP $1600,Y     ; In actor slot?
         BNE C38D95      ; Try next if not
         REP #$20        ; 16-bit A
         LDA $E7         ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable actors
         AND.L C3A456,X  ; Has our actor?
         SEP #$20        ; 8-bit A
         BEQ C38DA6      ; Skip if not
         LDA $E7         ; Actor slot
         STA $2180       ; Add to new list
         BRA C38DA6      ; Do next actor

; Fork: Try next actor in SRAM block
C38D95:  REP #$21        ; 16-bit A; C-
         TYA             ; Actor's address
         ADC #$0025      ; Point to next
         TAY             ; Reindex it
         SEP #$20        ; 8-bit A
         INC $E7         ; Actor slot +1
         LDA $E7         ; Actor slot
         CMP #$10        ; Done all 16?
         BNE C38D74      ; Loop if not

; Fork: Handle next eligible actor
C38DA6:  LDX $F3         ; List slot
         INX             ; List slot +1
         CPX #$0010      ; Done all 16?
         BNE C38D68      ; Loop if not

; Fork: End and draw new list
C38DAE:  LDA #$FF        ; Terminator
         STA $2180       ; End list
         TDC             ; Clear A
         TAX             ; List slot: 1
C38DB5:  LDA $7E9E09,X   ; Actor in slot
         BMI C38DDC      ; Exit if none
         PHX             ; Save slot
         PHX             ; Save slot
         REP #$20        ; 16-bit A
         ASL A           ; Actor x2
         TAX             ; Index it
         LDA.L C370DB,X  ; Actor address
         STA $67         ; Memorize it
         PLX             ; List slot
         TXA             ; Put in A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C38DDD,X  ; Position
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C3356A      ; Draw name
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000E      ; Done all 14?
         BNE C38DB5      ; Loop if not
C38DDC:  RTS

; Draw all gear info except compatible actors
C38DFB:  JSR C371D5      ; Clear BG3 map B
         JSR C3D252      ; Color: Blue
         LDX #C394CC     ; Text ptrs loc
         LDA #$0E        ; Strings: 14
         JSR C3712C      ; Draw Vigor, etc.
         LDX #C394E8     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C3714E      ; Draw Speed, etc.

; Fork: Draw stat modifiers
C38E18:  JSR C3D24D      ; Color: User's
         JSR C3CF26      ; Selected item
         JSR C38AA2      ; Compute index
;        TDC             ; Terminator
         STA $7E9E8D     ; Set mod B3
         STA $7E9E8E     ; Set mod B4
         LDY #$8445      ; Tilemap ptr
         JSR C335E1      ; Set position
;        TDC             ; Clear A
         LDA $D85010,X   ; Stat mods LB
         PHA             ; Memorize them
         AND #$0F        ; Vigor index
         ASL A           ; Double it
         JSR C38FC0      ; Draw modifier
         LDY #$84C5      ; Tilemap ptr
         JSR C335E1      ; Set position
;        TDC             ; Clear A
         PLA             ; Stat mods LB
         AND #$F0        ; Speed index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38FC0      ; Draw modifier
         LDY #$8545      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDX $4216       ; Item index
;        TDC             ; Clear A
         LDA $D85011,X   ; Stats mods HB
         PHA             ; Memorize them
         AND #$0F        ; Stamina index
         ASL A           ; Double it
         JSR C38FC0      ; Draw modifier
         LDY #$85C5      ; Tilemap ptr
         JSR C335E1      ; Set position
;        TDC             ; Clear A
         PLA             ; Stat mods HB
         AND #$F0        ; Mag.Pwr index
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         JSR C38FC0      ; Draw modifier

; Fork: Draw defensive properties
C38E8D:  JSR itm_cl2     ; Item class
         DEC A           ; Weapon?
         BEQ C38ED0      ; Branch if so
         LDA $D85014,X   ; Defense
         JSR C30563      ; Turn into text
         LDX #$86C3      ; Text position
         JSR C30543      ; Draw 3 digits
         LDX $4216       ; Item index
         LDA $D85015,X   ; Mag.Def
         JSR C30563      ; Turn into text
         LDX #$87C3      ; Text position
         JSR C30543      ; Draw 3 digits
         JSR C38F75      ; Draw evasions
         JSR C3902A      ; Draw 50% elems
         JSR C390E3      ; Draw other ones
         JSR C3D252      ; Color: Blue
         LDX #C394F0     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C3714E      ; Draw elem types
         BRA C38F51      ; Do spell taught

; Fork: Draw offensive properties
C38ED0:  JSR C38F26      ; Draw Bat.Pwr
         JSR C38F75      ; Draw evasions
         JSR C3D252      ; Color: Blue
         LDY #C3958A     ; Text pointer
         JSR C30326      ; Draw "Attack"
         JSR C3902A      ; Draw elements
         JSR C3D24D      ; Color: User's
         LDX $4216       ; Item index
         LDA $D85013,X   ; Allows Runic?
         PHA             ; Push properties
         PHA             ; Push properties
         BPL C38EF8      ; Branch if not
         LDY #C3959D     ; Text pointer
         JSR C302F9      ; Draw "Runic"
C38EF8:  PLA             ; Properties
         ASL A           ; 2-hand OK?
         BPL C38F0B      ; Branch if not
         LDY #C395A9     ; Text pointer
         JSR C302F9      ; Draw "2-hand"
C38F0B:  PLA             ; Properties
         AND #$02        ; Can SwdTech?
         BEQ C38F74      ; Exit if not
         LDY #C39591     ; Text pointer
         JMP C302F9      ; Draw "SwdTech"

; Draw weapon's Bat.Pwr in gear data menu
C38F26:  JSR C3CF26      ; Item
         CMP #$16        ; Soul Sabre?
         BEQ C38F4A      ; Hide if so
         CMP #$1C        ; Atma Weapon?
         BEQ C38F4A      ; Hide if so
         CMP #$51        ; Dice?
         BEQ C38F4A      ; Hide if so
         CMP #$52        ; Fixed Dice?
         BEQ C38F4A      ; Hide if so
         LDA $D85014,X   ; Bat.Pwr
         JSR C30563      ; Turn into text
         LDX #$8643      ; Text position
         JMP C30543      ; Draw 3 digits

; Fork: Hide power
C38F4A:  LDY #C394F8     ; Text pointer
         JMP C302F9      ; Draw "???"

; Draw spell taught by armor, including learning rate
C38F51:  JSR C3D24D      ; Color: User's
         LDX $4216       ; Item index
         REP #$20        ; 16-bit A
         LDA $D85003,X   ; Spell and rate
         STA $E0         ; Memorize them
         SEP #$20        ; 8-bit A
         XBA             ; Rate = 0?
         BEQ C38F74      ; Exit if so
         LDY #$82EF      ; Tilemap ptr
         JSR C335E1      ; Set position
         JMP C36142      ; Draw string
C38F74:  RTS

; Draw Evade and MBlock modifiers for gear data menu
C38F75:  LDY #$8743      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDX $4216       ; Item index
         TDC             ; Clear A
         LDA $D8501A,X   ; Evasion mods
         PHA             ; Memorize them
         AND #$0F        ; Evade index
         ASL A           ; x2
         ASL A           ; x4
         JSR C38FA4      ; Draw modifier
         LDY #$8843      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDX $4216       ; Item index
         TDC             ; Clear A
         PLA             ; Evasion mods
         AND #$F0        ; MBlock index
         LSR A           ; ÷2
         LSR A           ; ÷4
C38FA4:  TAX             ; Index it
         LDA.L C38FDE,X  ; Sign
         STA $7E9E8B     ; Add to string
         REP #$20        ; 16-bit A
         LDA.L C38FDE+1,X; Modifiger
         STA $7E9E8C     ; Add to string
         BRA C38FD1      ; Draw modifier

; Draw a non-evasion stat modifier for gear data menu
C38FC0:  TAX             ; Modifier index
         REP #$20        ; 16-bit A
         LDA.L C3900A,X  ; Sign and modifier
         STA $7E9E8B     ; Add to string
C38FD1:  SEP #$20        ; 8-bit A
         LDY #$9E89      ; Source LBs
         LDA #$7E        ; Source HB
         JMP C302FD      ; Draw modifier

; Build and draw list of attack or halved elements
C3902A:  LDX $4216       ; Item index
         LDA $D8500F,X   ; Elements
         JSR C39038      ; Build list
         LDX #$7BCD      ; Tilemap ptr
         BRA C39088      ; Draw list

; Build and draw list of absorbed, nulled, and weak elements
C390E3:  LDX $4216       ; Item index
         LDA $D85016,X   ; Absorbed elements
         JSR C39038      ; Build list
         LDX #$7BE9      ; Tilemap ptr
         JSR C39088      ; Draw list
         LDX $4216       ; Item index
         LDA $D85017,X   ; Nulled elements
         JSR C39038      ; Build list
         LDX #$7CCD      ; Tilemap ptr
         JSR C39088      ; Draw list
         LDX $4216       ; Item index
         LDA $D85018,X   ; Weak points
         JSR C39038      ; Build list
         LDX #$7CE9      ; Tilemap ptr
;        BRA C39088      ; Draw list

; Draw current list of elements
C39088:  STX $EB         ; Set dest LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dest HB
         TDC             ; Clear A
         TAX             ; Index: 0
C3908A:  TDC             ; Clear A
         LDA $7EAA8D,X   ; Element to draw
         BMI C390B0      ; Exit if no more
         PHX             ; Save list index
         REP #$20        ; 16-bit A
         ASL A           ; Element x2
         TAX             ; Index it
         LDA.L C390B1,X  ; Tilemap data
         JSR C390C1      ; Draw element
         LDA $EB         ; Tilemap ptr
         CLC             ; ...
         ADC #$0004      ; Skip 2 tiles
         STA $EB         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; List index
         INX             ; List index +1
         CPX #$0006      ; Done 6 entries?
         BNE C3908A      ; Loop if not
C390B0:  RTS

; Base tile attributes for each element
C390B1:  dw $3580        ; Water
         dw $3584        ; Earth
         dw $3588        ; Pearl
         dw $358C        ; Wind
         dw $3590        ; Poison
         dw $3594        ; Lightning
         dw $3598        ; Ice
         dw $359C        ; Fire

; Build current list of elements
C39038:  LDY #$AA8D      ; 7E/AA8D
         STY $2181       ; Set WRAM LBs
         STZ $E0         ; Current: Water
         LDY #$0008      ; Elements: 8
C39043:  ROL A           ; Draw current?
         BCC C3904D      ; Skip it if not
         PHA             ; Save elements
         LDA $E0         ; Current element
         STA $2180       ; Add to list
         PLA             ; Elements left
C3904D:  INC $E0         ; Elem number +1
         DEY             ; One less left
         BNE C39043      ; Loop till last
         LDA #$FF        ; Terminator
         STA $2180       ; End list
         RTS

; Draw current element
C390C1:  STA [$EB]       ; Set NW tile
         LDY #$0040      ; Map ptr: SW
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set SW tile
         LDY #$0002      ; Map ptr: NE
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set NE tile
         LDY #$0042      ; Map ptr: SE
         INC A           ; Tile num +1
         STA [$EB],Y     ; Set SE tile
C3910C:  RTS

; 64: Sustain non-shifted gear data menu
C3910D:  LDA $08         ; Pushing A?
         BMI C39119      ; Branch if so
         LDA $09         ; No-autofire keys
         BIT #$02        ; Pushing left?
         BEQ C39132      ; Branch if not
C39119:  LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$FFF4      ; Speed: -12
         STY $9C         ; Set scroll speed
         LDA #$5E        ; C3/9170
         STA $27         ; Queue: Moved menu
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Pan screen
         JMP C30F1D      ; Sound: Click

; Fork: Handle B
C39132:  LDA $09         ; Pushing B?
         BPL C3910C      ; Exit if not
         LDA #$FF        ; Status: Off
         STA $99         ; Disable arrow
         LDX #$7B49      ; Tilemap ptr
         LDY #$0500      ; Bytes: 1280
         JSR clr_ram     ; Clear BG3b
         LDA #$04        ; Show cursor: Y
         TSB $45         ; Set menu flag
         JSR C3CB5_      ; Create scrollbar
         JSR desc_on     ; Description: On
         JSR C30FA4      ; Queue BG3 upload
         JSR C313D3      ; Upload it now
         TDC             ; BG1 H-Shift: 0
         STA $7E9A10     ; Unhide item list
         JSR C38C9B      ; Next: Choice 1
         JMP C30F14      ; Sound: Cursor

; 5E: Sustain shifted gear data menu
C39170:  LDA $09         ; No-autofire keys
         BIT #$81        ; Using B or right?
         BEQ C3910C      ; Exit if not
C3917C:  JSR C30F14      ; Sound: Cursor
         LDA #$0A        ; Frames: 10
         STA $20         ; Set scroll timer
         LDY #$000C      ; Speed: 12
         STY $9C         ; Set scroll speed
         LDA #$64        ; C3/910D
         STA $27         ; Queue screen 1
         LDA #$65        ; C3/37AF
         STA $26         ; Next: Pan screen
;        BRA C38D20      ; Create arrow

; Create arrow for gear data menu
C38D20:  LDA #$01        ; Status: On
         STA $99         ; Enable arrow
         LDY #C381AD     ; C3/81AD
         JSR qanim1      ; Queue OAM fn
         LDY #$8008      ; Pos: 8, 128
         JMP objpos      ; Set sprite's

; Draw item usage menu
C39198:  JSR C371BC      ; Clear BG2 map A
         LDX #C391C5     ; C3/91C5
         JSR boxes_      ; Upload windows
         JSR C371AD      ; Clear BG1 map B
         LDY #$FFC0      ; X: -64 = 448
         STY $35         ; Set BG1 X-Pos
         LDA #$02        ; Portrait row bit
         TSB $45         ; Ignore back row
         JSR C33225      ; Draw party info
         JSR C391D1      ; Draw item info
         JMP up_txt      ; Upload text maps

; Draw item info for item usage menu
C391D1:  JSR C3D24D      ; Color: User's
         LDY #C395B5     ; Text pointer
         JSR C30326      ; Draw "Owned:"
         LDY #$78CB      ; Tilemap ptr
         JSR C335E1      ; Set position
         JSR C3CF26      ; Selected item
         JSR C3CFC3      ; Load name
         JSR C387B9      ; Draw name

; Draw quantity owned for item usage menu
C391F7:  JSR C3D24D      ; Color: User's
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         JSR C30563      ; Turn into text
         LDX #$7A93      ; Text position
         JMP C30539      ; Draw 2 digits

; 6F: Initialize item usage menu
C3920E:  JSR C32B11      ; Init variables
         JSR C39198      ; Draw menu
         JSR C30833      ; Queue cursor OAM
         LDA #$40        ; No cursor memory
         TSB $45         ; Set menu flag
         LDA #$70        ; Queue: Sustain menu
         JMP C32B40      ; Next: Fade-in

; 70: Sustain item usage menu
C39220:  JSR C30F68      ; Queue stats upload
         JSR C30FCC      ; And item info's
         LDA $08         ; Pushing A?
         BPL C39236      ; Branch if not
         JSR C393B5      ; Item
         CMP #$E7        ; Rename Card?
         BEQ C3924A      ; Branch if so
         JSR C39271      ; Handle item usage

; Fork: Handle B
C39236:  LDA $09         ; Pushing B?
         BPL C39249      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C3923F:  LDA #$42        ; Allow back row
         TRB $45         ; And cursor memory
         LDA #$77        ; C3/1B9B
         STA $27         ; Queue Item menu
         STZ $26         ; Next: Fade-out
C39249:  RTS

; Fork: Rename Card
C3924A:  JSR C32DA6      ; Define Y
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C3926A      ; Fail if so
         STY $0206       ; Save actor adr
         JSR C30F1D      ; Sound: Click
         LDA #$FE        ; Actor renaming
         STA $0205       ; Set next menu
         JSR fdexit      ; Queue menu exit
         LDA #$E7        ; Item number
         JMP C3A5A5      ; Destroy item

; Fork: Prevent guest renaming
C3926A:  JMP C3C5C6      ; Buzzer + Mosaic

; Handle item usage, excluding Rename Card
C39271:  JSR C32DA6      ; Target's address
         JSR C392C7      ; Valid target?
         BCC C39294      ; Fail if not
         JSR C30F50      ; Play heal sound
         JSR C3929B      ; Heal & destroy
         JSR C391F7      ; Redraw quantity
         JSR C32C9C      ; Redraw party
         TDC             ; Clear A
         LDA $28         ; Item's slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         BNE C39249      ; Exit if not 0
         BRA C3923F      ; Close submenu
C39294:  JMP C3C5C6      ; Buzzer + Mosaic

; Heal item's target, destroy item
C3929B:  JSR C392A4      ; Heal target
         JSR C393B5      ; Selected item
         JMP C3A5A5      ; Destroy item

; Adjust item target's HP, MP, and status
C392A4:  LDA $0014,Y     ; Status LB
         STA $F8         ; Set target's
         LDA $0015,Y     ; Status HB
         STA $FB         ; Set target's
         PHY             ; Save index
         JSR C393B5      ; Item number
         LDX #$0002      ; Mode: Item
         JSL $C20009     ; Get new status
         PLY             ; Actor's address
         LDA $FC         ; Status LB
         STA $0014,Y     ; Set actor's
         LDA $FF         ; Status HB
         STA $0015,Y     ; Set actor's
         JMP C393BD      ; Heal HP & MP

; Determine whether item target is valid
C392C7:  LDA $0014,Y     ; Wound status?
         BMI C3930F      ; Branch if so
         JSR C393B5      ; Item
         CMP #$FE        ; Dried Meat?
         BEQ C3934E      ; Branch if so
         CMP #$E8        ; Tonic?
         BEQ C3934E      ; Branch if so
         CMP #$E9        ; Potion?
         BEQ C3934E      ; Branch if so
         CMP #$EA        ; X-Potion?
         BEQ C3934E      ; Branch if so
         CMP #$EB        ; Tincture?
         BEQ C3935F      ; Branch if so
         CMP #$EC        ; Ether?
         BEQ C3935F      ; Branch if so
         CMP #$ED        ; X-Ether?
         BEQ C3935F      ; Branch if so
         CMP #$F1        ; Revivify?
         BEQ C39318      ; Branch if so
         CMP #$F2        ; Antidote?
         BEQ C39345      ; Branch if so
         CMP #$F3        ; Eyedrop?
         BEQ C39321      ; Branch if so
         CMP #$F4        ; Soft?
         BEQ C3932A      ; Branch if so
         CMP #$F5        ; Remedy?
         BEQ C3933C      ; Branch if so
         CMP #$EE        ; Elixir?
         BEQ C3936F      ; Branch if so
         CMP #$F8        ; Green Cherry?
         BEQ C39333      ; Branch if so
         CMP #$F6        ; Sleeping Bag?
         BNE C3935A      ; Fail if not
         BRA C3939B      ; Handle S.Bag

; Fork: Fenix Down
C3930F:  JSR C393B5      ; Item
         CMP #$F0        ; Fenix Down?
         BEQ C3936D      ; Succeed if so
         BRA C3935A      ; Make item fail

; Fork: Revivify
C39318:  LDA $0014,Y     ; Status
         AND #$02        ; Zombie?
         BEQ C3935A      ; Fail if not
         BRA C3936D      ; Make item work

; Fork: Eyedrop
C39321:  LDA $0014,Y     ; Status
         LSR A           ; Dark?
         BCC C3935A      ; Fail if not
         BRA C3936D      ; Make item work

; Fork: Soft
C3932A:  LDA $0014,Y     ; Status
         ASL A           ; Petrify?
         BPL C3935A      ; Fail if not
         BRA C3936D      ; Make item work

; Fork: Green Cherry
C39333:  LDA $0014,Y     ; Status
         AND #$20        ; Imp?
         BEQ C3935A      ; Fail if not
         BRA C3936D      ; Make item work

; Fork: Remedy
C3933C:  LDA $0014,Y     ; Dark? Poison?
         AND #$65        ; Imp? Petrify?
         BEQ C3935A      ; Fail if none
         BRA C3936D      ; Make item work

; Fork: Antidote
C39345:  LDA $0014,Y     ; Status
         AND #$04        ; Poison?
         BEQ C3935A      ; Fail if not
         BRA C3936D      ; Make item work

; Fork: Dried Meat, Tonic, Potion, X-Potion
C3934E:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C3935A      ; Fail if any
         JSR C32C35      ; At full HP?
         BCC C3936D      ; Succeed if not

; Fork: Make item fail
C3935A:  CLC             ; Mark failure
         RTS

; Fork: Tincture, Ether, X-Ether
C3935F:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C3935A      ; Fail if any
         JSR C32C57      ; At full MP?
         BCS C3935A      ; Fail if so

; Fork: Make item work
C3936D:  SEC             ; Mark success
         RTS

; Fork: Elixir
C3936F:  LDA $0014,Y     ; Zombie? KO?
         AND #$C2        ; Or Petrify?
         BNE C3935A      ; Fail if any
         JSR C32C35      ; At full HP?
         BCC C3936D      ; Succeed if not
         JSR C32C57      ; At full MP?
         BCC C3936D      ; Succeed if not
         BRA C3935A      ; Make item fail

; Fork: Sleeping Bag
C3939B:  LDA $0014,Y     ; Dark/Zom/Pois?
         AND #$F7        ; Clear/Imp/Pet/KO?
         BNE C3936D      ; Succeed if any
         LDA $0015,Y     ; Float status?
         BMI C3936D      ; Succeed if so
         JSR C32C35      ; At full HP?
         BCC C3936D      ; Succeed if not
         JSR C32C57      ; At full MP?
         BCC C3936D      ; Succeed if not
         BRA C3935A      ; Make item fail

; Get selected recovery item
C393B5:  TDC             ; Clear A
         LDA $28         ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         RTS

; Handle HP and MP recovery from item
C393BD:  JSR C393B5      ; Item
         JSR C38AA2      ; Compute index
         JSR C39457      ; Load item power
         LDA $D85013,X   ; Fixed healing?
         PHA             ; Save properties
         BMI C39400      ; Branch if not
         AND #$08        ; Affects HP?
         BEQ C393E6      ; Branch if not

; Fork: Fixed HP healing
C393D7:  TYX             ; Actor's address
         REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         ADC $09,X       ; Add target's HP
         STA $09,X       ; Set target's HP
         JSR C32C35      ; Enforce max HP

; Fork: Fixed MP healing
C393E6:  PLA             ; Properties
         AND #$10        ; Affects MP?
         BEQ C3945F      ; Exit if not
         REP #$21        ; 16-bit A; C-
         LDA $B2         ; Item's power
         BRA C3942_      ; Restore MP

; Fork: Fractional HP healing
C39400:  AND #$08        ; Affects HP?
         BEQ C3942A      ; Branch if not
         LDX $0B,Y       ; Max HP
         JSR C30DD0      ; Add gear bonus
         JSR C30DFD      ; Cap at 9999
         JSR C39460      ; Max HP x Pwr/16
         TYX             ; Actor's address
         ADC $09,X       ; Add target's HP
         STA $09,X       ; Set target's HP
         JSR C32C35      ; Enforce max HP

; Fork: Fractional MP healing
C3942A:  PLA             ; Properties
         AND #$10        ; Affects MP?
         BEQ C3945F      ; Exit if not
         LDX $0F,Y       ; Max MP
         JSR C30DD0      ; Add gear bonus
         JSR C30E0A      ; Cap at 999
         JSR C39460      ; Max MP x Pwr/16
C3942_:  TYX             ; Actor's address
         ADC $0D,X       ; Add target's MP
         STA $0D,X       ; Set target's MP
         JMP C32C57      ; Enforce max MP

; Load recovery item's power
C39457:  LDA $D85014,X   ; Item's power
         STA $B2         ; Memorize it
         STZ $B3         ; Clear HB
C3945F:  RTS

; Multiply max HP or MP by item's power, divide by 16
C39460:  PHY             ; Save Y
         LDY $F3         ; Max HP or MP
         LDA $B2         ; Item's power
         JSR mul16       ; Power x max
         STX $E9         ; Set gain LBs
         STA $EB         ; Set gain B3
         STZ $EC         ; Clear byte 4
         REP #$20        ; 16-bit A
         LDX #$0004      ; Loop counter
.loop    LSR $EB         ; Halve HB
         ROR $E9         ; Halve LBs w/ C
         DEX             ; Counter -1
         BNE .loop       ; Loop till 0
         PLY             ; Restore Y
         LDA $E9         ; Product
         CLC             ; Prepare ADC
         RTS

; Load navigation data for Equip menu options
C395C5:  LDY #C395D4     ; C3/95D4
         JMP C30681      ; Load navig data

; Handle D-Pad for Equip menu options
C395CB:  JSR C307B0      ; Handle D-Pad
C395CE:  LDY #C395D9     ; C3/95D9
         JMP C306C3      ; Relocate cursor

; Load navigation data for Equip menu slot selection
C395E1:  LDY #C395F0     ; C3/95F0
         JMP C30681      ; Load navig data

; Handle D-Pad for Equip menu slot selection
C395E7:  JSR C307B0      ; Handle D-Pad
C395EA:  LDY #C395F5     ; C3/95F5
         JMP C306C3      ; Relocate cursor

; Load navigation data for equipment browsing
C395FD:  LDY #C3961B     ; C3/961B
         JMP C30681      ; Load navig data

; Handle D-Pad for equipment browsing (over 9 items)
C39603:  JSR C38948      ; Handle D-Pad
C39606:  LDY #C39620     ; C3/9620
         JMP C306CB      ; Relocate cursor

; Handle D-Pad for equipment browsing (9 items or less)
C39612:  JSR C307B0      ; Handle D-Pad
C39615:  LDY #C39620     ; C3/9620
         JMP C306C3      ; Relocate cursor

; Load navigation data for Relic menu options
C39632:  LDY #C39641     ; C3/9641
         JMP C30681      ; Load navig data

; Handle D-Pad for Relic menu options
C39638:  JSR C307B0      ; Handle D-Pad
C3963B:  LDY #C39646     ; C3/9646
         JMP C306C3      ; Relocate cursor

; Load navigation data for relic slot selection
C3964A:  LDY #C39659     ; C3/9659
         JMP C30681      ; Load navig data

; Handle D-Pad for relic slot selection
C39650:  JSR C307B0      ; Handle D-Pad
C39653:  LDY #C3965E     ; C3/965E
         JMP C306C3      ; Relocate cursor

; Draw party gear overview
C39662:  JSR C371BC      ; Clear BG2 map A
         LDX #C397D7     ; C3/97D7
         JSR C303C4      ; Draw window
         JSR C30EBD      ; Upload window
         LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C39691      ; Handle member 1
         JSR C396B8      ; Handle member 2
         JSR C396E1      ; Handle member 3
         JSR C3970A      ; Handle member 4
         JSR C30E93      ; Upload BG1 A+B
         JSR C371D0      ; Clear BG3 map A
         JMP C30ED9      ; Upload BG3 A+B

; Draw text in party gear overview for member 1
C39691:  LDA $69         ; Nobody here?
         BMI C39732      ; Exit if so
         JSR C3658A      ; Color: Blue
         LDX #C3A9F8     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw body parts
         LDX $6D         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$38CD      ; Text position
         JSR C3356A      ; Draw actor name
         STZ $28         ; Member slot: 1
         LDA #$04        ; Base Y: 4
         BRA C39733      ; Draw equipment

; Draw text in party gear overview for member 2
C396B8:  LDA $6A         ; Nobody here?
         BMI C39732      ; Exit if so
         JSR C3658A      ; Color: Blue
         LDX #C3AA04     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw body parts
         LDX $6F         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$3ACD      ; Text position
         JSR C3356A      ; Draw actor name
         LDA #$01        ; Member: 2
         STA $28         ; Set member slot
         LDA #$0C        ; Base Y: 12
         BRA C39733      ; Draw equipment

; Draw text in party gear overview for member 3
C396E1:  LDA $6B         ; Nobody here?
         BMI C39732      ; Exit if so
         JSR C3658A      ; Color: Blue
         LDX #C3AA10     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw body parts
         LDX $71         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$3CCD      ; Text position
         JSR C3356A      ; Draw actor name
         LDA #$02        ; Member: 3
         STA $28         ; Set member slot
         LDA #$14        ; Base Y: 20
         BRA C39733      ; Draw equipment
C39732:  RTS

; Draw text in party gear overview for member 4
C3970A:  LDA $6C         ; Nobody here?
         BMI C39732      ; Exit if so
         JSR C3658A      ; Color: Blue
         LDX #C3AA1C     ; Text ptrs loc
         LDA #$06        ; Strings: 6
         JSR C3714E      ; Draw body parts
         LDX $73         ; Actor's address
         STX $67         ; Memorize it
         JSR C3D24D      ; Color: User's
         LDY #$3ECD      ; Text position
         JSR C3356A      ; Draw actor name
         LDA #$03        ; Member: 4
         STA $28         ; Set member slot
         LDA #$1C        ; Base Y: 28

; Draw member's gear in party gear overview
C39733:  STA $E2         ; Set base Y
         LDY $67         ; Actor's address
         TDC             ; Clear A
         TAX             ; 1st: R-Hand
C3973B:  PHX             ; Push gear slot
         PHY             ; Push actor adr
         PHY             ; Push actor adr
         STZ $E5         ; X-Pos HB: 0
         LDA.L C3977E,X  ; X position
         STA $E4         ; Memorize it
         LDA.L C39784,X  ; Relative Y
         CLC             ; Prepare ADC
         ADC $E2         ; Add base Y
         LDX $E4         ; X position
         JSR C38820      ; Compute map ptr
         STZ $E0         ; Forbid "Empty"
         LDA $05,S       ; Gear slot
         CMP #$02        ; Either hand?
         BCS C39767      ; Branch if not
         JSR C39C0C      ; Test "Empty"
C39767:  PLY             ; Actor's address
         LDA $001F,Y     ; Item in slot
         JSR C39C68      ; Draw its name
         PLY             ; Actor's address
         INY             ; Reach next slot
         PLX             ; Gear slot
         INX             ; Point to next
         CPX #$0006      ; Done 6 slots?
         BNE C3973B      ; Loop if not
         RTS

; Load equipped item's name
C3978A:  CMP #$FF        ; Empty item?
         BNE C397A5      ; Draw if not
         LDA $E0         ; Allow "Empty"?
         BEQ C397C8      ; Blank if not
         LDA #$FF        ; Empty item
C397A5:  JMP C3CFC3      ; Load name

; Fork: Blank item name
C397C8:  JSR wm9E8B      ; WRAM: 7E/9E8B
         LDY.W #!itm_ns  ; Spaces: 9
         JMP spaces      ; Add to string

; Draw Equip menu, create portrait, update status via gear
C397DB:  JSR C3983C      ; Do boxes; face
         JSR C398C4      ; Draw info; status
         JSR C3D252      ; Color: Blue
         LDX #C3AABC     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3714E      ; Draw Head, Body
         JSR C397F7      ; Draw top options
         JSR C30ED9      ; Upload BG3 A+B
         JMP C3A61D      ; Queue text upload

; Draw options in Equip menu
C397F7:  JSR C3D24D      ; Color: User's
         LDX #C3AAB4     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JMP C3714E      ; Draw text

; Draw options in Relic menu
C39805:  JSR C3D24D      ; Color: User's
         LDX #C3AAC0     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JMP C3714E      ; Draw text

; Draw Relic menu, memorize original relics, create portrait
C39813:  JSR C3983C      ; Do boxes; face
         JSR C39BE1      ; Define Y
         LDX $23,Y       ; Relics worn
         STX $B0         ; Save for Reequip
         JSR C398DA      ; Draw info; status
         JSR C3D252      ; Color: Blue
         LDX #C3AAC4     ; Text ptrs loc
         LDA #$02        ; Strings: 2
         JSR C3714E      ; Draw 2x "Relic"
         JSR C39805      ; Draw menu options
         JSR C3AFEE      ; Build desc map
         JMP C30ED9      ; Upload BG3 A+B

; Draw elements shared by Equip and Relic menus, create portrait
C3983C:  JSR C398B9      ; Load actor stats
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         SEP #$20        ; 8-bit A
         LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$42        ; 32x64 at $8000
         STA $2109       ; Set BG3 map loc
         JSR C39DFB      ; Reset BG2 X-Pos
         JSR bg2b_cl     ; Clear BG2 A+B
         LDX #C39C6E     ; C3/9C6E
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C30E93      ; Upload BG1 A+B
         JSR bg3b_cl     ; Clear BG3 A+B
         JSR C39BCE      ; Draw actor name
         JSR C36808      ; Create portrait
         JSR C3D252      ; Color: Blue
         LDX #C3AB44     ; Text ptrs loc
         LDA #$0E        ; Strings: 14
         JSR C3712C      ; Draw Vigor, etc.
         LDX #C3AB60     ; Text ptrs loc
         LDA #$04        ; Strings: 4
         JSR C3714E      ; Draw Speed, etc.
         JMP C30ED9      ; Upload BG3 A+B

; Load member's stats and properties with gear
C398B9:  TDC             ; Clear A
         LDA $28         ; Member slot
         TAX             ; Index it
         LDA $69,X       ; Actor
         JSL $C20006     ; Load data
         RTS

; Draw actor info in Equip menu, update status based on gear
C398C4:  JSR C3A164      ; Draw hand names
         JSR C398E7      ; Do stats; status
         JSR C399D6      ; Draw relic FX
         JSR C39BEB      ; Draw arms
         JSR C39C24      ; Draw helmet
         JMP C39C32      ; Draw armor

; Draw actor info in Relic menu, update status based on gear
C398DA:  JSR C398E7      ; Do stats; status
         JSR C39C40      ; Draw relic 1
         JMP C39C4E      ; Draw relic 2

; Draw current stats in gear menu, update status based on gear
C398E7:  JSR C3D24D      ; Color: User's
         JSR C398B9      ; Load actor stats
         JSR C39BE1      ; Actor's address
         JSR C3A1D7      ; Set Bat.Pwr mode
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         JSR C399B0      ; Relocate stats
         JSR C3996D      ; Update status
         PEA $7E37       ; Pos for Mag.Pwr
         PEA $7DB7       ; Pos for Stamina
         PEA $7D37       ; Pos for Speed
         PEA $7CB7       ; Pos for Vigor
         PEA $7FB7       ; Pos for Evade
         PEA $80B7       ; Pos for MBlock
         LDX #$000A      ; 1st: MBlock
.loop    STX $FE         ; Save stat index
         LDA $3000,X     ; Stat value
         JSR C30563      ; Turn into text
         PLX             ; Text position
         JSR C30543      ; Draw 3 digits
         LDX $FE         ; Stat index
         DEX             ; Stat index -1
         DEX             ; Stat index -1
         BPL .loop       ; Loop till < 0
         JSR C39B94      ; Define Bat.Pwr
         LDX $F1         ; Load it
         STX $F3         ; Save for $05B1
         JSR C305B1      ; Turn into text
         LDX #$7EB7      ; Text position
         JSR C30509      ; Draw 3 digits
         LDA $301A       ; Defense
         JSR C30563      ; Turn into text
         LDX #$7F37      ; Text position
         JSR C30543      ; Draw 3 digits
         LDA $301B       ; Mag.Def
         JSR C30563      ; Turn into text
         PLB             ; Restore DB
         LDX #$8037      ; Text position
         JMP C30543      ; Draw 3 digits

; Update status based on gear (Rage denotes Auto Float)
C3996D:  JSR C39BE1      ; Actor's address
         LDA $3032       ; Gear immunity
         JSR C39995      ; Deny ailments
         LDA $3034       ; Gear auto status
         ORA $15,X       ; Add actor status
         LSR A           ; Auto Float or Rage?
         BCC C39994      ; Exit if not
         LDA $3034       ; Gear auto status
         AND #$01        ; Auto Float?
         BEQ C39991      ; No status if so
         LDA #$81        ; Enable Rage, Float
C39991:  STA $15,X       ; Set actor status
C39994:  RTS

; Cure ailments blocked by gear
C39995:  AND #$25        ; Dark, Poison, Imp
         EOR #$FF        ; Toggle all bits
         STA $E1         ; Save immunities
         TYX             ; Actor's address
         LDA $14,X       ; Actor's status
         AND $E1         ; Lift immune ones
         STA $14,X       ; Save changes
         RTS

; Grant Float status if bestowed by gear
C399A4:  AND #$01        ; Auto Float
         LSR A           ; Put in Carry
         ROR A           ; Put in bit 7
         ORA $15,X       ; Add status
         STA $15,X       ; Set status
         RTS

; Load actor's info for Equip or Relic menu
C399B0:  LDX #$003F      ; Buffer index
C399B4:  LDA $11A0,X     ; Actor info
         STA $3000,X     ; Set as current
         DEX             ; Index -1
         BPL C399B4      ; Loop till < 0
         LDA $A1         ; 2-hand flag
         STA $A0         ; Set as current
         LDA $CD         ; Genji G. flag
         STA $CE         ; Set as current
         RTS

; Draw relic effects in Equip menu
C399D6:  LDY #C3ABD6     ; Text pointer
         JSR C30326      ; Blank effect A
         LDY #C3ABDF     ; Text pointer
         JSR C30326      ; Blank effect B
         LDA $11D8       ; Gear effects
         AND #$20        ; Merit Award?
         BEQ C399F2      ; Branch if not
         JSR C3D252      ; Color: Blue
         LDY #C3ABE8     ; Text pointer
         JSR C30326      ; B: "Heavy gear"
C399F2:  LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C39A02      ; Branch if not
         JSR C3D252      ; Color: Blue
         LDY #C3ABF1     ; Text pointer
         JSR C30326      ; A: "Dual wield"
C39A02:  LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C39A12      ; Exit if not
         JSR C3D252      ; Color: Blue
         LDY #C3ABFA     ; Text pointer
         JSR C30326      ; B: "Two-handed"
C39A12:  JMP C3D24D      ; Color: User's
                         ; ^ For gear

; Draw projected stats in Equip or Relic menu
C39A1C:  LDA $7E9D89     ; Empty item list?
         BEQ C39A27      ; Abort if so
         JSR C3A231      ; On a gray item?
         BCS C39A2A      ; Branch if not
C39A27:  JMP C3A476      ; Clear stats
C39A2A:  JSR C39BE1      ; Actor's address
         LDA $25         ; Submenu
         CMP #$02        ; Equip menu?
         BEQ C39A37      ; Branch if so
         INY             ; Point to L-Hand
         INY             ; Point to head
         INY             ; Point to body
         INY             ; Point to relic 1
C39A37:  JSR C3A239      ; Y = Actor address
         JSR ldgear1     ; X = Stock slot
         LDA $001F,Y     ; Equipped item
         PHA             ; Preserve it
         LDA $1869,X     ; Inventory item
         STA $001F,Y     ; Put on actor
         PHY             ; Save actor adr
         JSR C398B9      ; Load actor data
         JSR C39BE1      ; Base actor adr
         JSR C3A1D7      ; Set Bat.Pwr mode
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
         JSR C39B09      ; Set stat colors
         LDA $11A6       ; New Vigor
         JSR C30563      ; Turn into text
         LDX #$7CBF      ; Text position
         LDA $3040       ; Vigor palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11A4       ; New Speed
         JSR C30563      ; Turn into text
         LDX #$7D3F      ; Text position
         LDA $3041       ; Speed palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11A2       ; New Stamina
         JSR C30563      ; Turn into text
         LDX #$7DBF      ; Text position
         LDA $3042       ; Stamina palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11A0       ; New Mag.Pwr
         JSR C30563      ; Turn into text
         LDX #$7E3F      ; Text position
         LDA $3043       ; Mag.Pwr palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         JSR C39B5A      ; Define Bat.Pwr
         JSR C305B1      ; Turn into text
         LDX #$7EBF      ; Text position
         LDA $3048       ; Bat.Pwr palette
         STA $29         ; Set as current
         JSR C30509      ; Draw 3 digits
         LDA $11BA       ; New Defense
         JSR C30563      ; Turn into text
         LDX #$7F3F      ; Text position
         LDA $3044       ; Defense palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11A8       ; New Evade
         JSR C30563      ; Turn into text
         LDX #$7FBF      ; Text position
         LDA $3045       ; Evade palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11BB       ; New Mag.Def
         JSR C30563      ; Turn into text
         LDX #$803F      ; Text position
         LDA $3046       ; Mag.Def palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         LDA $11AA       ; New MBlock
         JSR C30563      ; Turn into text
         LDX #$80BF      ; Text position
         LDA $3047       ; MBlock palette
         STA $29         ; Set as current
         JSR C30543      ; Draw 3 digits
         PLB             ; Restore DB
         PLX             ; Actor address
         PLA             ; Original item
         STA $1F,X       ; Restore gear
         RTS

; Set color for each projected stat in Equip or Relic menu
C39B09:  TDC             ; Clear A
         TAX             ; Stat index: 0
C39B10:  LDA.L C39B52,X  ; Stat pointer
         PHX             ; Save index
         TAX             ; Index pointer
         LDA $11A0,X     ; Projected stat
         CMP $3000,X     ; Matches old?
         BEQ C39B25      ; Branch if so
         BCC C39B29      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39B2B      ; Color: Yellow

; Fork: Use player's color
C39B25:  LDA #$20        ; Palette 0
         BRA C39B2B      ; Skip a line

; Fork: Gray out statistic
C39B29:  LDA #$24        ; Palette 1
C39B2B:  PLX             ; Stat index
         STA $3040,X     ; Set stat color
         INX             ; Stat index +1
         CPX #$0008      ; Done 8 stats?
         BNE C39B10      ; Loop if not

; Fork: Handle Bat.Pwr
C39B35:  JSR C39B5A      ; Set new Bat.Pwr
         JSR C39B94      ; Set old Bat.Pwr
         LDY $F3         ; New Bat.Pwr
         CPY $F1         ; Matches old?
         BEQ C39B47      ; Branch if so
         BCC C39B4B      ; Gray if less
         LDA #$28        ; Palette 2
         BRA C39B4D      ; Font: Yellow

; Fork: Use player's color for Bat.Pwr
C39B47:  LDA #$20        ; Palette 0
         BRA C39B4D      ; Skip a line

; Fork: Gray out Bat.Pwr
C39B4B:  LDA #$24        ; Palette 1
C39B4D:  STA $3048       ; Set BP color
         RTS

; Ordered index list for loading stats
C39B52:  db $06          ; Vigor
         db $04          ; Speed
         db $02          ; Stamina
         db $00          ; Mag.Pwr
         db $1A          ; Defense
         db $08          ; Evade
         db $1B          ; Mag.Def
         db $0A          ; MBlock

; Define current (Status) or projected (Equip, Relic) Bat.Pwr
C39B5A:  LDA $A1         ; 2-hand mode?
         BEQ C39B74      ; Branch if not
         LDA $11AC       ; R-Hand's power
         BEQ C39B6A      ; Branch if 0
         STA $11AD       ; Set as L-Hand's
         BRA C39B83      ; Combine hands

; Fork: Two-handing L-Hand weapon
C39B6A:  LDA $11AD       ; L-Hand's power
         STA $11AC       ; Set as R-Hand's
         BRA C39B83      ; Combine hands

; Fork: Not two-handing a weapon
C39B74:  LDA $CD         ; Got Genji Glove?
         BNE C39B83      ; Branch if so
         LDA $11AC       ; R-Hand's power
         BEQ C39B83      ; Branch if 0
         STZ $11AD       ; L-Hand power: 0

; Fork: Combine hands' Bat.Pwr
C39B83:  LDA $11AC       ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $11AD       ; Add L-Hand's
         STA $F3         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ROL A           ; +1 if overflow
         STA $F4         ; Set Bat.Pwr HB
         RTS

; Define current Bat.Pwr for Equip or Relic menu
C39B94:  LDA $A0         ; 2-hand mode?
         BEQ C39BAE      ; Branch if not
         LDA $300C       ; R-Hand's power
         BEQ C39BA4      ; Branch if 0
         STA $300D       ; Set as L-Hand's
         BRA C39BBD      ; Combine hands

; Fork: Two-handing L-Hand weapon
C39BA4:  LDA $300D       ; L-Hand's power
         STA $300C       ; Set as R-Hand's
         BRA C39BBD      ; Combine hands

; Fork: Not two-handing a weapon
C39BAE:  LDA $CE         ; Got Genji Glove?
         BNE C39BBD      ; Branch if so
         LDA $300C       ; R-Hand's power
         BEQ C39BBD      ; Branch if 0
         STZ $300D       ; L-Hand power: 0

; Fork: Combine hands' Bat.Pwr
C39BBD:  LDA $300C       ; R-Hand's power
         CLC             ; Prepare ADC
         ADC $300D       ; Add L-Hand's
         STA $F1         ; Set Bat.Pwr LB
         TDC             ; Zero A
         ROL A           ; +1 if overflow
         STA $F2         ; Set Bat.Pwr HB
         RTS

; Draw actor name and class in Equip or Relic menu
C39BCE:  JSR C39BE1      ; Actor's address
         JSR C3D24D      ; Color: User's
         LDY #$7AEF      ; Text position
         JSR C3356A      ; Draw actor name
         LDY #$7B6F      ; Text position
         JMP C33580      ; Draw actor class

; Draw equipped armaments in Equip menu
C39BEB:  JSR C39C0C      ; Test Empty x2
         LDX #$79DB      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         LDA $1F,X       ; R-Hand item
         JSR C39C68      ; Draw name
         JSR C39C0C      ; Test Empty x2
         LDX #$7A5B      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         LDA $20,X       ; L-Hand item
         BRA C39C68      ; Draw name

; Check if "Empty" should be drawn for both hands
C39C0C:  JSR C39BE1      ; Actor address
         STZ $E0         ; Forbid "Empty"
         LDA $1F,X       ; R-Hand item
         INC A           ; Nothing?
         BNE C39C20      ; Forbid if not
         LDA $20,X       ; L-Hand item
         INC A           ; Nothing?
         BNE C39C20      ; Forbid if not
         INC $E0         ; Allow "Empty"
C39C20:  RTS

; Draw equipped helmet in Equip menu
C39C24:  LDX #$7ADB      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $21,X       ; Helmet
         BRA C39C68      ; Draw its name

; Draw equipped armor in Equip menu
C39C32:  LDX #$7B5B      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $22,X       ; Armor
         BRA C39C68      ; Draw its name

; Draw equipped relic 1 in Relic menu
C39C40:  LDX #$7ADB      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $23,X       ; Relic 1
         BRA C39C68      ; Draw its name

; Draw equipped relic 2 in Relic menu
C39C4E:  LDX #$7B5B      ; Tilemap ptr
         JSR C39C5C      ; Set X, coords
         STZ $E0         ; Forbid "Empty"
         LDA $24,X       ; Relic 2
C39C68:  JSR C3978A      ; Load item name
         JMP C387B_      ; Draw item name

; Set text position and load actor data address
C39C5C:  REP #$20        ; 16-bit A
         TXA             ; Tilemap ptr
         STA $7E9E89     ; Set position
C39BE1:  SEP #$20        ; 8-bit A
         JSR C32D9E      ; Actor's address
         STY $67         ; Memorize it
         TYX             ; Copy it to X
         RTS

; Set to condense text for party gear overview or final battle lineup
C39C86:  LDY #C39DC7     ; Source LBs
         LDA #$C3        ; Source HB
         JMP bg1v        ; Queue BG1 V-Pan

; Set to condense text in Equip or Relic menu
C39CA5:  LDY #C39DC7     ; C3/9DC7
         JSR bg3v_       ; Queue BG3 V-Pan
         JSR C39D0F      ; Load BG1 V-Data
         LDX #$000C      ; Base index
C39CC8:  LDA.L C39D53,X  ; BG1 H-Pan data
         STA $7E9BC9,X   ; Save in RAM
         DEX             ; Index -1
         BPL C39CC8      ; Loop till < 0
         LDY #$9BC9      ; Src: 7E/9BC9
         JSR bg1h_       ; Queue BG1 H-Pan
         LDY #$9849      ; Src: 7E/9849
         JMP bg1v_       ; Queue BG1 V-Pan

; Load BG1 vertical shift table for Equip or Relic menu
C39D0F:  LDX $00         ; Index: 0
C39D11:  LDA.L C39D60,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0012      ; At item data?
         BNE C39D11      ; Loop if not
C39D1F:  LDA.L C39D60,X  ; Scanline data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         TDC             ; Clear A
         LDA $49         ; BG1 top row
         JSR x16         ; x16
         REP #$21        ; 16-bit A; C-
         ADC.L C39D60,X  ; Add V-Pan data
         STA $7E9849,X   ; Save in RAM
         SEP #$20        ; 8-bit A
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0063      ; Beyond list?
         BNE C39D1F      ; Loop if not
C39D44:  LDA.L C39D60,X  ; Void's V-Data
         STA $7E9849,X   ; Save in RAM
         INX             ; Index +1
         CPX #$0067      ; End of table?
         BNE C39D44      ; Loop if not
         RTS

; Switch to layout with options in Equip or Relic menu
C39DFB:  JSR C39E4C      ; Erase title
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         RTS

; Switch to layout without options in Equip or Relic menu
C39E03:  JSR C39E4C      ; Erase options
         LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         JMP C3D252      ; Color: Blue
                         ; ^ For "Equip"

; 36: Handle Equip menu options
C39E10:  JSR C39DFB      ; Switch windows
         JSR C397F7      ; Draw options
         JSR C395CB      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C39E24      ; Branch if not
         JSR C30F1D      ; Sound: Click
         BRA C39E53      ; Handle selection

; Fork: Handle B
C39E24:  LDA $09         ; Pushing B?
         BPL C39E37      ; Branch if not
         JSR C398B9      ; Update field FX
         LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         JMP C30F14      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C39E37:  LDA #$35        ; Init cmd: C3/1C1E
         JMP C32088      ; Handle L and R

; Draw blue "Equip" in Equip or Relic menu
C39E3E:  LDY #C3AB0E     ; Text pointer
         JMP C30326      ; Draw title

; Draw blue "Remove" in Equip or Relic menu
C39E45:  LDY #C3AB14     ; Text pointer
         JMP C30326      ; Draw title

; Erase options and title in Equip or Relic menu
C39E4C:  LDY #$78D1      ; Tilemap ptr
         JSR C335E1      ; Set position
         LDY #$001A      ; Spaces: 26
         JMP spacedr     ; Draw 26 spaces

; Handle selected option in Equip menu
C39E53:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C39E5B,X)  ; Handle option

; Jump table for the above
C39E5B:  dw C39E63       ; EQUIP
         dw C39E74       ; OPTIMUM
         dw C39E7D       ; RMOVE
         dw C39E8E       ; EMPTY

; Handle "EQUIP" selection in Equip menu
C39E63:  JSR C39E03      ; Switch windows
         JSR C39E3E      ; Draw blue "EQUIP"
         JSR C395E1      ; Load navig data
         JSR C395EA      ; Relocate cursor
         LDA #$55        ; C3/A073
         STA $26         ; Next: Slot choice
         RTS

; Handle "OPTIMUM" selection in Equip menu
C39E74:  JSR C39EDF      ; Optimize gear
         JSR C398C4      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Handle "RMOVE" selection in Equip menu
C39E7D:  JSR C39E03      ; Switch windows
         JSR C39E45      ; Draw blue "REMOVE"
         JSR C395E1      ; Load navig data
         JSR C395EA      ; Relocate cursor
         LDA #$56        ; C3/A0BE
         STA $26         ; Next: Slot choice
         RTS

; Handle "EMPTY" selection in Equip menu
C39E8E:  JSR C39E97      ; Remove gear
         JSR C398C4      ; Redo text, status
         STZ $4D         ; Cursor: "USE"
         RTS

; Remove character's equipment
C39E97:  JSR C39BE1      ; Actor address
         LDY #$0004      ; Gear slots: 4
.loop    LDA $1F,X       ; Item in slot
         JSR C3A56C      ; Put in stock
         LDA #$FF        ; Empty item
         STA $1F,X       ; Clear slot
         INX             ; Gear slot +1
         DEY             ; One less left
         BNE .loop       ; Loop till body
         RTS

; Optimize member's equipment (event command)
C39EC1:  JSR C37087      ; Get party info
         LDX #$0003      ; Member slot: 4
         LDA $0201       ; Actor to equip
C39EC9:  CMP $69,X       ; In member slot?
         BEQ C39ED5      ; Branch if so
         DEX             ; Member slot -1
         BPL C39EC9      ; Loop till last
         STP             ; Freeze game...
C39ED5:  TXA             ; Member slot
         STA $28         ; Memorize it
         JSR C39EDF      ; Optimize gear
         RTL

; Optimize character's equipment
C39EDF:  JSR C398B9      ; Get gear FX
         JSR C39E97      ; Remove gear
         JSR C39BE1      ; Actor's address
         STY $F3         ; Memorize it
         LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C39F09      ; Branch if not

; Fork: Put a two-handed weapon in R-Hand
C39EF1:  JSR C39F84      ; Get valid items
         JSR C3A95E      ; Sort by power
         JSR C3A02E      ; Pick 2H weapon
         LDX $F3         ; Actor's address
         STA $1F,X       ; Set R-Hand item
         JSR C3A5A5      ; Adjust stock
         BRA C39F5A      ; Handle helmet

; Fork: Put a weapon in R-Hand
C39F09:  JSR C39F84      ; Get valid items
         JSR C3A95E      ; Sort by power
         JSR C3A008      ; Pick a weapon
         STA $1F,X       ; Put in R-Hand
         JSR C3A5A5      ; Adjust stock
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BNE C39F40      ; Branch if so

; Fork: Put a shield in L-Hand
C39F26:  JSR C39FC6      ; Get valid items
         JSR C3A95E      ; Sort by defense
         JSR C3A008      ; Pick a shield
         STA $20,X       ; Put in L-Hand
         JSR C3A5A5      ; Adjust stock
         BRA C39F5A      ; Handle helmet

; Fork: Put a weapon in L-Hand
C39F40:  JSR C39F84      ; Get valid items
         JSR C3A95E      ; Sort by power
         JSR C3A008      ; Pick a weapon
         STA $20,X       ; Put in L-Hand
         JSR C3A5A5      ; Adjust stock

; Fork: Optimize helmet
C39F5A:  JSR C3A3A1      ; Get valid items
         JSR C3A95E      ; Sort by defense
         JSR C3A008      ; Choose helmet
         STA $21,X       ; Put on actor
         JSR C3A5A5      ; Adjust stock

; Fork: Optimize armor
C39F6F:  JSR C3A3DD      ; Get valid items
         JSR C3A95E      ; Sort by defense
         JSR C3A008      ; Choose armor
         STA $22,X       ; Put on actor
         JMP C3A5A5      ; Adjust stock

; Select first non-excluded item in sorted list of compatible gear
C3A008:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAY             ; RAM index: 0
C3A010:  TDC             ; Clear A
         TAX             ; ROM index: 0
C3A012:  PHX             ; Save index
         TDC             ; ...
         LDA $9D8A,Y     ; Stock slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C3A02B      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C3A012      ; Loop if not
         PLB             ; Restore DB
         LDX $F3         ; Actor's address
         RTS             ; Exit
C3A02B:  INY             ; RAM index +1
         BRA C3A010      ; Try next item

; Exclusions: Cursed Shld, Thornlet, Imp set, Atma Weapon, Drainer, Soul Sabre, Heal Rod


; Select first two-handed weapon from sorted list of compatible gear
C3A02E:  LDA $7E9D89     ; List size
         BEQ C3A070      ; Branch if 0
         STA $CB         ; Memorize it
         STZ $CC         ; Clear its HB
         TDC             ; Clear A
         TAY             ; RAM index: 0
C3A03A:  TDC             ; Clear A
         TAX             ; ROM index: 0
C3A03C:  PHX             ; Save index
         TYX             ; RAM index
         JSR ldgear3     ; Item in slot
         PLX             ; ROM index
         CMP $ED82E4,X   ; Excluded?
         BEQ C3A067      ; Skip if so
         INX             ; ROM index +1
         CPX #$000A      ; Tested 10?
         BNE C3A03C      ; Loop if not
         STA $C9         ; Save item
         JSR C38AA2      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3A067      ; Skip if not
         LDA $C9         ; Item
         RTS

; Fork: Try next weapon, ignore Gauntlet if no valid options
C3A067:  INY             ; RAM index +1
         CPY $CB         ; End of list?
         BNE C3A03A      ; Loop if not
         BRA C3A008      ; Pick 1H weapon

; Fork: Default to empty item
C3A070:  LDA #$FF        ; Empty item
         RTS

; 55: Handle selection of gear slot to fill
C3A073:  JSR C395E7      ; Handle D-Pad
         JSR C3A164      ; Recolor hand names
         LDA $08         ; Pushing A?
         BPL C3A0A3      ; Branch if not
         JSR C30F1D      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$57        ; C3/A0FE
         STA $26         ; Next: Item list
         JSR C3A348      ; Build item list
         JSR C3A95E      ; Sort it by power
         JSR C3A2DA      ; Cursor & Scrollbar
         LDA #$55        ; Return here if..
         STA $27         ; ..list is empty
         JSR C39A1C      ; Draw stat preview
         JSR C371A9      ; Blank item list
         JSR C313D3      ; Refresh screen
         JMP C3A49B      ; Draw item list

; Fork: Handle B
C3A0A3:  LDA $09         ; Pushing B?
         BPL C3A0B7      ; Branch if not
         JSR C395C5      ; Load navig data
         JSR C395CE      ; Relocate cursor
         LDA #$36        ; C3/9E10
         STA $26         ; Next: Option list
         JMP C30F14      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A0B7:  LDA #$7E        ; Init cmd: C3/1C4B
         JMP C32088      ; Handle L and R

; 56: Handle manual gear removal
C3A0BE:  JSR C395E7      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A0E3      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JSR C39BE1      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TXA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAX             ; Index sum
         LDA $1F,X       ; Item in slot
         JSR C3A56C      ; Put in stock
         LDA #$FF        ; Empty item
         STA $1F,X       ; Clear gear slot
         JSR C398C4      ; Redo text, status

; Fork: Handle B
C3A0E3:  LDA $09         ; Pushing B?
         BPL C3A0F7      ; Branch if not
         JSR C395C5      ; Load navig data
         JSR C395CE      ; Relocate cursor
         LDA #$36        ; C3/9E10
         STA $26         ; Next: Option list
         JMP C30F14      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A0F7:  LDA #$7F        ; Init cmd: C3/1C59
         JMP C32088      ; Handle L and R

; 57: Handle gear browsing
C3A0FE:  JSR C3A2C2      ; Handle navigation
         JSR C39A1C      ; Draw stat preview
         LDA $08         ; Pushing A?
         BPL C3A133      ; Branch if not
         JSR C3A231      ; On a gray item?
         BCC C3A15D      ; Fail if so
         JSR C30F1D      ; Sound: Click
         LDA $001F,Y     ; Item to unequip
         JSR C3A56C      ; Put in stock
         JSR ldgear1     ; Chosen item
         STA $001F,Y     ; Equip on actor
         JSR C3A5A5      ; Adjust stock
         JSR C398C4      ; Redo text, status
         BRA C3A13C      ; Exit gear list

; Fork: Handle B
C3A133:  LDA $09         ; Pushing B?
         BPL C3A15C      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C3A13C:  JSR C3A476      ; Clear stat preview
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         JSR C395E1      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C395EA      ; Relocate cursor
         LDA #$55        ; C3/A073
         STA $26         ; Next: Body parts
C3A15C:  RTS

; Fork: Invalid selection
C3A15D:  JMP C3C5C6      ; Buzzer + Mosaic

; Draw "R-hand" and "L-hand" in Equip menu
C3A164:  LDA $11D8       ; Gear effects
         AND #$08        ; Gauntlet?
         BEQ C3A17E      ; Branch if not
         JSR C39BE1      ; Actor address
         LDA $1F,X       ; R-Hand item
         INC A           ; None?
         BEQ C3A195      ; Branch if so
         LDA $20,X       ; L-Hand item
         INC A           ; None?
         BEQ C3A1B9      ; Branch if so

; Fork: Draw both hands in blue
C3A17E:  JSR C3D252      ; Color: Blue
         JSR C3A187      ; Draw "R-hand"
         BRA C3A18E      ; Draw "L-hand"

; Fork: Check if L-Hand also empty
C3A195:  LDA $20,X       ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3A17E      ; Blue x2 if so

; Fork: Check if two-handed weapon in L-Hand
C3A19E:  JSR C38AA2      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3A17E      ; Blue x2 if not
         JSR C3658A      ; Color: Gray
         JSR C3A187      ; Draw "R-hand"
         JSR C3D252      ; Color: Blue
         BRA C3A18E      ; Draw "L-hand"

; Fork: Check if two-handed weapon in R-Hand
C3A1B9:  LDA $1F,X       ; R-Hand item
         JSR C38AA2      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3A17E      ; Blue x2 if not
         JSR C3D252      ; Color: Blue
         JSR C3A187      ; Draw "R-hand"
         JSR C3658A      ; Color: Gray
;        BRA C3A18E      ; Draw "L-hand"

; Fork: Draw "L-hand"
C3A18E:  LDY #C3AACE     ; Text pointer
         JMP C30326      ; Draw "L-hand"

; Fork: Draw "R-hand"
C3A187:  LDY #C3AAC8     ; Text pointer
         JMP C30326      ; Draw "R-hand"

; Define Bat.Pwr mode (normal, doubled, or combined hands)
C3A1D7:  STZ $CD         ; Genji mode off
         LDA $11D8       ; Gear effects
         BIT #$10        ; Genji Glove?
         BEQ C3A1E2      ; Branch if not
         INC $CD         ; Pwr: Merge hands
C3A1E2:  STZ $A1         ; Power x2: Off
;        LDA $11D8       ; Gear effects
         BIT #$08        ; Gauntlet?
         BEQ C3A1FB      ; Exit if not
         TYX             ; Actor's address
         LDA $1F,X       ; R-Hand item
         INC A           ; None?
         BEQ C3A1FD      ; Branch if so
         LDA $20,X       ; L-Hand item
         INC A           ; None?
         BEQ C3A21A      ; Branch if so
C3A1FB:  RTS

; Fork: Check if L-Hand also empty
C3A1FD:  LDA $20,X       ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3A1FB      ; Exit if so

; Fork: Check if two-handed weapon in L-Hand
C3A206:  BRA C3A21_      ; Skip a line

; Fork: Check if two-handed weapon in R-Hand
C3A21A:  LDA $1F,X       ; R-Hand item
C3A21_:  JSR C38AA2      ; Compute index
         LDA $D85013,X   ; Properties
         ASL A           ; 2-hand OK?
         BPL C3A1FB      ; Exit if not
         INC $A1         ; Power: x2
         RTS

; Check if pointing at grayed out gear
C3A231:  JSR C3A239      ; Actor address
         TDC             ; Clear A
         LDA $4B         ; Gear list slot
         BRA C3A245      ; Analyze item

; Load address to selected body slot
C3A239:  JSR C39BE1      ; Actor's address
C3A23_:  REP #$21        ; 16-bit A; C-
         TYA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $5F         ; Add body slot
         TAY             ; Move it to Y
         RTS

; Determine whether gear list entry is disabled
C3A245:  JSR ldgear2     ; Item in slot
         JSR itm_cl1     ; Item class
         STA $F6         ; Memorize it
         LDA $5F         ; Body slot
         DEC A           ; L-Hand/relic 2?
         BEQ C3A294      ; Branch if so
         BPL C3A2B2      ; If head or body

; Fork: For R-Hand or relic 1
C3A268:  LDA $0020,Y     ; L-Hand item
         BRA C3A29_      ; Skip a line

; Fork: For L-Hand or relic 2
C3A294:  LDA $001E,Y     ; R-Hand item
C3A29_:  CMP #$FF        ; None?
         BEQ C3A2B2      ; Enable if so
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BEQ C3A2B4      ; Branch if so
         LDA $11D8       ; Gear effects
         AND #$10        ; Genji Glove?
         BEQ C3A2B4      ; Branch if not
C3A2B2:  SEC             ; Set to enable
         RTS

; Fork: Prevent two shields or weapons
C3A2B4:  JSR itm_cl2     ; Held item's class
         CMP $F6         ; Like list item's?
         BNE C3A2B2      ; Enable if not
C3A2C0:  CLC             ; Set to disable
         RTS

; Handle D-Pad plus L and R for gear browsing
C3A2C2:  LDA $7E9D89     ; List size
         CMP #$0A        ; Over 9 items?
         BCS C3A2CD      ; Branch if so
         JMP C39612      ; Handle D-Pad

; Fork: Scrollable list
C3A2CD:  LDA #$05        ; List type: Gear
         STA $2A         ; Set redraw mode
         JSR C31FCA      ; Handle L and R
         BCS C3A2C0      ; Exit if pushed
         JMP C39603      ; Handle D-Pad

; Initialize cursor data for list of available gear
C3A2DA:  STZ $4A         ; List scroll: 0
         LDA $7E9D89     ; Number of items
         BEQ C3A2C0      ; Exit if none
         PHA             ; Memorize it
         CMP #$0A        ; Over 9?
         BCS C3A2F5      ; Branch if so
         JSR C3A5D2      ; Duplicate cursor
         JSR C395FD      ; Load navig data
         PLA             ; Number of items
         STA $54         ; Set cursor limit
         JMP C39615      ; Relocate cursor

; Fork: Scrollable list
C3A2F5:  JSR C3A5D2      ; Duplicate cursor
         LDX #$6000      ; Bar range: 60 px
         STX $4204       ; Set dividend
         LDA $01,S       ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $4206       ; Set divisor
         JSR x32r        ; 16-bit A; cycles
         STZ $4F         ; List col/row: 1
         SEP #$20        ; 8-bit A
         LDY $4214       ; V-Spd = Quotient
         LDA #$60        ; Y: 96
         JSR C309B8      ; Create scrollbar
         JSR C395FD      ; Load navig data
         JSR C39606      ; Relocate cursor
         PLA             ; Number of items
         SEC             ; Prepare SBC
         SBC #$09        ; Deduct page size
         STA $5C         ; Set scroll limit
         LDX #$0109      ; Onscreen rows: 9
         STX $5A         ; Onscreen cols: 1
         RTS

; Compile compatible weapons for Optimum
C39F84:  PEA $0101       ; Seek: Weapons
         BRA eq_comp     ; Build list

; Compile compatible shields for Optimum
C39FC6:  PEA $0303       ; Seek: Shields
         BRA eq_comp     ; Build list

; Compile compatible gear for selected body part
C3A348:  LDA $4B         ; Cursor slot
         CMP #$02        ; Either hand?
         BCC C3A361      ; Branch if so
         BEQ C3A3A1      ; Or if helmet

; Compile compatible armor
C3A3DD:  PEA $0202       ; Seek: Armor
         BRA eq_comp     ; Build list

; Compile compatible helmets
C3A3A1:  PEA $0404       ; Seek: Helmets
         BRA eq_comp     ; Build list

; Compile compatible weapons and shields
C3A361:  PEA $0103       ; Seek: Wpn/Shld
         BRA eq_comp     ; Build list

; Compile compatible relics
C3A85F:  PEA $0505       ; Seek: Relics
eq_comp: JSR C3A419      ; Init list
         JSR C3A430      ; Define compat
         JSR C3D24D      ; Color: User's
         LDY $00         ; Item slot: 1
.loop    LDA $1869,Y     ; Item in slot
         CMP #$FF        ; None?
         BEQ .next       ; Skip if so
         JSR itm_cl1     ; Item class
         CMP $01,S       ; Sought type A?
         BEQ .compat     ; Branch if so
         CMP $02,S       ; Sought type B?
         BNE .next       ; Skip if not
.compat  REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         BIT $E7         ; Actor can use?
         BEQ .next       ; Skip if not
         SEP #$20        ; 8-bit A
         TYA             ; Item slot
         STA $2180       ; Add to list
         INC $E0         ; List size +1
.next    SEP #$20        ; 8-bit A
         INY             ; Item slot +1
         CPY #$00FF      ; Done 255?...
         BNE .loop       ; Loop if not
         LDA $E0         ; List size
         STA $7E9D89     ; Save to list
         PLX             ; Clean stack
         RTS

; Initialize list of compatible gear
C3A419:  LDX #$0008      ; List slot: 9
C3A41D:  STA $7E9D8A,X   ; Add to list
         DEX             ; List slot -1
         BPL C3A41D      ; Loop till < 0
         STZ $E0         ; List size: 0
wm9D8A:  LDX #$9D8A      ; 7E/9D8A
         STX $2181       ; Set WRAM LBs
         RTS

; Defaulting to item slot 256, which was likely inaccessible at some point during
; development, provides a fallback for Optimum in case the list is empty or contains
; only banned items such as Cursed Shld. This introduces a bug that allows anything
; to be equipped on a given body part.


; Define gear compatibility for actor
C3A430:  JSR C39BE1      ; Actor address
;        TDC             ; Clear A
         LDA $00,X       ; Actor
C3A437:  ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3A456,X  ; Compat bit
         STA $E7         ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $11D8       ; Gear effects
         AND #$20        ; Merit Award?
         BEQ C3A455      ; Exit if not
         LDA #$80        ; M.Award bit
         TSB $E8         ; Add to compat
C3A455:  RTS

; Bitfield for actor slots
C3A456:  dw $0001        ; Terra
         dw $0002        ; Locke
         dw $0004        ; Cyan
         dw $0008        ; Shadow
         dw $0010        ; Edgar
         dw $0020        ; Sabin
         dw $0040        ; Celes
         dw $0080        ; Strago
         dw $0100        ; Relm
         dw $0200        ; Setzer
         dw $0400        ; Mog
         dw $0800        ; Gau
         dw $1000        ; Gogo
         dw $2000        ; Umaro
         dw $4000        ; Guest 1
         dw $8000        ; Guest 2

; Erase projected stats in Equip or Relic menu
C3A476:  TDC             ; Clear A
         TAX             ; 1st: Vigor
         LDY #$0009      ; Stats: 9
         REP #$20        ; 16-bit A
C3A47D:  STA $7E7CBF,X   ; Clear hundreds
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear tens
         INX             ; Index +1
         INX             ; Index +1
         STA $7E7CBF,X   ; Clear ones
         INX             ; Index +1
         INX             ; Index +1
         TXA             ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$007A      ; Row +2, col -3
         TAX             ; Reindex it
         DEY             ; One less stat
         BNE C3A47D      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Draw and reveal list of available gear for body part
C3A49B:  LDA $7E9D89     ; Empty list?
         BEQ C3A4CC      ; Abort if so
         JSR C38B78      ; Define $E5, $E6
         TDC             ; Clear A
         LDA $7E9D89     ; List size
         CMP #$09        ; Over 8 items?
         BCC C3A4AF      ; Branch if not
         LDA #$09        ; Rows left: 9
C3A4AF:  TAY             ; Put in Y...
C3A4B0:  PHY             ; Memorize it
         JSR C3A4D1      ; Draw item name
         INC $E5         ; List slot +1
         JSR e6add2      ; BG1 WR row +2
         PLY             ; Rows left
         DEY             ; One less left
         BNE C3A4B0      ; Loop till last
         REP #$20        ; 16-bit A
         TDC             ; BG1 H-Shift: 0
         STA $7E9BD0     ; Unhide gear list
         SEP #$20        ; 8-bit A
         RTS             ; Exit
C3A4CC:  LDA $27         ; Old menu mode
         STA $26         ; Set as current
         RTS

; Draw item's name and quantity for list of available gear
C3A4D1:  JSR C3A239      ; Actor's address
         TDC             ; Clear A
         LDA $E5         ; Gear list slot
         JSR C3A245      ; Gray out item?
         BCS C3A4E0      ; Branch if not
         LDA #$28        ; Color: Gray
         BRA C3A4E2      ; Skip a line
C3A4E0:  LDA #$20        ; Color: User's
C3A4E2:  STA $29         ; Set palette
         TDC             ; Clear A
         LDA $E5         ; Gear list slot
         TAX             ; Index it
         LDA $7E9D8A,X   ; Inventory slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         JSR C30563      ; Turn into text
         LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         LDX #$000C      ; X: 12
         JSR C38820      ; Compute map ptr
         JSR C30539      ; Draw 2 digits
         LDA $E6         ; BG1 write row
         LDX #$0002      ; X: 2
         JSR C38820      ; Compute map ptr
;        TDC             ; Clear A
         LDA $E5         ; Gear list slot
         TAY             ; Put it in Y
         JSR C3A51A      ; Load "<item>:"
         JMP C387B_      ; Draw "<item>:"

; Load name of item from list of available gear, add a colon
C3A51A:  JSR wm9E8B      ; WRAM: 7E/9E8B
         TYX             ; Gear list slot
         JSR ldgear3     ; Item in slot
         CMP #$FF        ; None?
         BEQ C3A55D      ; Blank if so
         JMP C3884F      ; Load "<item>:"

; Fork: Blank item slot
C3A55D:  LDY.W #!itm_ns+3; Spaces: 12
         JMP spaces      ; Add to string

; Add item to inventory
C3A56C:  PHY             ; Save Y
         STA $E0         ; Set item to add
         LDY $00         ; Item slot: 1
C3A571:  CMP $1869,Y     ; Slot holds it?
         BEQ C3A598      ; Qty +1 if so
         CMP #$FF        ; Empty item?
         BEQ C3A5A3      ; Exit if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C3A571      ; Loop if not

; Fork: Find an empty slot
C3A580:  LDY $00         ; Item slot: 1
C3A582:  LDA $1869,Y     ; Item in slot
         INC A           ; None?
         BEQ C3A58C      ; Replace if so
         INY             ; Item slot +1
         BRA C3A582      ; Try next slot

; Fork: Put item in empty slot
C3A58C:  LDA $E0         ; Item to add
         STA $1869,Y     ; Put in slot
         LDA #$01        ; Quantity: 1
         BRA C3A5A0      ; Assign to slot

; Fork: Quantity +1
C3A598:  LDA $1969,Y     ; Quantity owned
         CMP #$63        ; 99?
         BEQ C3A5A3      ; Exit if so
         INC A           ; Quantity +1
C3A5A0:  STA $1969,Y     ; Save changes
C3A5A3:  PLY             ; Restore Y
         RTS

; Remove item from inventory
C3A5A5:  PHX             ; Save X
         LDX $00         ; Item slot: 1
C3A5AA:  CMP $1869,X     ; Slot holds it?
         BEQ C3A5B7      ; Branch if so
         INX             ; Item slot +1
         CPX #$0100      ; Done all 256?
         BNE C3A5AA      ; Loop if not
         PLX             ; Restore X
         RTS

; Fork: Quantity -1
C3A5B7:  DEC $1969,X     ; Quantity -1
         BNE C3A5D0      ; Exit if > 0
         LDA #$FF        ; Empty item
         STA $1869,X     ; Put in slot
C3A5D0:  PLX             ; Restore X
         RTS

; Duplicate cursor before browsing gear
C3A5D2:  LDY #C3A5EB     ; C3/A5EB
         JSR qanim2      ; Queue OAM fn
C3A5D_:  LDY $55         ; Cursor pos
         JMP objpos      ; Set dupe's

; Update cursor indicating selected gear slot
C3A5EB:  BNE C3A60E      ; If mode 1

; Mode 0: Initialize cursor
C3A5F3:  LDA #$01        ; Dupe: Sustain
         TSB $46         ; Set menu flag
         LDY #C30912     ; Anim table ptr
         JSR anm_c3      ; Set sprite's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain cursor
C3A60E:  LDA $46         ; Menu flags
         LSR A           ; Remove dupe?
         BCC C3A61B      ; Delete if so
         JMP oamsec      ; Set OAM; requeue
C3A61B:  CLC             ; Set to dequeue
         RTS

; Set to upload text tilemaps for Equip menu
C3A61D:  JSR C3A631      ; Queue BG3 upload
         JMP C30F68      ; Queue BG1 upload

; Set to upload text tilemaps for Relic menu
C3A622:  JSR C30F68      ; Queue BG1 upload
         LDA $021E       ; Frame counter
         LSR A           ; Odd value?
         BCS C3A631      ; Favor stats if so
         JMP C3B301      ; Queue desc upload

; Set to upload BG3 tilemaps A and upper B
C3A631:  LDY #$4000      ; $4000
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0880      ; Bytes: 2176
         STY $19         ; Set data size
         RTS

; 58: Initialize Relic menu
C3A659:  JSR C3A65E      ; Init variables
         BRA C3A67D      ; Draw menu, etc.

; Initialize variables for Relic menu
C3A65E:  JSR C335F7      ; Reset/Stop stuff
         JSR C3719C      ; Set Win1 bounds
         STZ $4A         ; List scroll: 0
         STZ $49         ; Top BG1 WR row: 1
         LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         STZ $99         ; Unmark Reequip
         JSR C31BFF      ; Queue desc anim
         JSR C39CA5      ; Set to shift text
         JSR C39632      ; Load navig data
         JSR C3963B      ; Relocate cursor
         JMP C30833      ; Queue cursor OAM

; Draw Relic menu, memorize original relics, etc.
C3A67D:  JSR C39813      ; Draw menu, etc.
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         LDA #$59        ; C3/A6C6
         STA $27         ; Queue: Option list
         JMP C33609      ; BRT:1 + NMI

; 79: Swap actor in Relic menu, retain Equip mode
C3A68B:  JSR C3A6A7      ; Draw menu, etc.
         JSR C39E3E      ; Draw blue "EQUIP"
         JSR C3A6B6      ; Cursor & Fade-in
         LDA #$5A        ; C3/A80B
         BRA C3A6C1      ; Queue: Slot list

; 7A: Swap actor in Relic menu, retain Remove mode
C3A699:  JSR C3A6A7      ; Draw menu, etc.
         JSR C39E45      ; Draw blue "REMOVE"
         JSR C3A6B6      ; Cursor & Fade-in
         LDA #$5C        ; C3/A918
         BRA C3A6C1      ; Queue: Slot list

; Reset Relic menu for either of the above
C3A6A7:  JSR C3A65E      ; Init variables
         JSR C39813      ; Draw menu, etc.
         JSR C30F68      ; Queue BG1 upload
         JSR C3A631      ; Queue BG3 upload
         JMP C39E03      ; Switch windows

; Put cursor on first relic slot, trigger fade-in
C3A6B6:  LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JSR C3964A      ; Load navig data
         JMP C39653      ; Relocate cursor

; Queue Equip or Remove mode after actor swap in Relic menu
C3A6C1:  STA $27         ; Set queued command
         JMP C33609      ; BRT:1 + NMI

; 59: Handle Relic menu options
C3A6C6:  JSR C3A631      ; Queue BG3 upload
         JSR C39DFB      ; Switch windows
         JSR C39805      ; Draw options
         JSR C39638      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A6DE      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JMP C3A7DD      ; Handle choice

; Fork: Handle B
C3A6DE:  LDA $09         ; Pushing B?
         BPL C3A6EA      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         JSR C3A6F9      ; Handle Reequip

; Fork: Handle L and R, prepare for menu reset
C3A6EA:  LDA #$58        ; Init cmd: C3/A659
         JMP C32088      ; Handle L and R

; Test Reequip activation, select menu commands accordingly
C3A6F9:  JSR C398B9      ; Get gear effects
         JSR C39BE1      ; Actor address
         LDA $00,X       ; Actor
         CMP #$0D        ; Umaro?
         BEQ C3A70D      ; Branch if so
         JSR C3A76A      ; Trigger Reequip?
         BCS C3A714      ; Branch if so
C3A70D:  LDA #$04        ; C3/1AF0
         STA $27         ; Queue main menu
         STZ $26         ; Next: Fade-out
         CLC             ; Reequip: N
         RTS

; Fork: Triggered Reequip
C3A714:  LDA #$06        ; Main cursor: Off
         TRB $46         ; Set menu flag
         JSR C30F68      ; Queue BG1 upload
         JSR C3A631      ; Queue BG3 upload
         JSR C3A72A      ; Handle text, etc.
         LDA #$F0        ; Frames: 240
         STA $22         ; Set fade delay
         LDA #$6C        ; C3/A7BF
         STA $26         ; Next: Late fade
         SEC             ; Reequip: Y
         RTS

; Handle Reequip activation
C3A72A:  JSR C39E4C      ; Erase top text
         LDY #C3AC33     ; Text pointer
         JSR C30326      ; Draw warning
         LDA $1D4E       ; Game options
         AND #$10        ; Optimum mode?
         BEQ C3A752      ; Branch if so

; Fork: Empty mode
C3A73A:  LDA #$6E        ; C3/1C8C
         STA $27         ; Queue removal
         LDA $26         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C3A74B      ; Branch if so
         LDY #C3AC1B     ; Text pointer
         JMP C30326      ; Draw "Empty"

; Fork: Draw "Empty" in option window
C3A74B:  LDY #C3AC03     ; Text pointer
         JMP C30326      ; Draw "Empty"

; Fork: Optimum mode
C3A752:  LDA #$6D        ; C3/1C80
         STA $27         ; Queue optimizing
         LDA $26         ; Menu mode
         CMP #$59        ; Relic options?
         BEQ C3A763      ; Branch if so
         LDY #C3AC26     ; Text pointer
         JMP C30326      ; Draw "Optimum"

; Fork: Draw "Optimum" in option window
C3A763:  LDY #C3AC0E     ; Text pointer
         JMP C30326      ; Draw "Optimum"

; Determine whether to trigger Reequip in Relic menu
C3A76A:  LDX $23,Y       ; Current relics
         CPX $B0         ; Unchanged?
         BEQ C3A7B7      ; Branch if so

; Fork: Compare old and new relics
C3A77D:  LDX #$0002      ; 1st: M.Award
.loop    LDA.L reequip,X ; Reequip item
         CMP $0023,Y     ; Relic 1?
         BEQ C3A7BA      ; Trigger if so
         CMP $0024,Y     ; Relic 2?
         BEQ C3A7BA      ; Trigger if so
         CMP $B0         ; Old relic 1?
         BEQ C3A7BA      ; Trigger if so
         CMP $B1         ; Old relic 2?
         BEQ C3A7BA      ; Trigger if so
         DEX             ; Item index -1
         BPL .loop       ; Loop till < 0
C3A7B7:  CLC             ; Reequip: No
         RTS             ; Exit
C3A7BA:  SEC             ; Reequip: Yes
         RTS

; Relics that trigger Reequip
reequip: db $D0          ; Gauntlet
         db $D1          ; Genji Glove
         db $DA          ; Merit Award

; 6C: Handle delayed fade-out for Reequip
C3A7BF:  LDA $22         ; Delay expired?
         BEQ C3A7DA      ; Fade if so
         DEC $22         ; Timer -1
         LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BNE C3A7DA      ; Fade if so
         LDA $09         ; Pushing B?
         BPL C3A7DC      ; Exit if not
C3A7DA:  STZ $26         ; Next: Fade-out
C3A7DC:  RTS

; Handle selected option in Relic menu
C3A7DD:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3A7E5,X)  ; Handle option

; Jump table for the above
C3A7E5:  dw C3A7E9       ; EQUIP
         dw C3A7FA       ; REMOVE

; Handle "EQUIP" selection in Relic menu
C3A7E9:  JSR C39E03      ; Switch windows
         JSR C39E3E      ; Draw blue "EQUIP"
         LDA #$5A        ; C3/A80B
;        STA $26         ; Next: Slot list
         BRA C3A7F_      ; Load navig data

; Handle "REMOVE" selection in Relic menu
C3A7FA:  JSR C39E03      ; Switch windows
         JSR C39E45      ; Draw blue "REMOVE"
         LDA #$5C        ; C3/A918
C3A7F_:  STA $26         ; Next: Slot list
         JSR C3964A      ; Load navig data
         JMP C39653      ; Relocate cursor

; 5A: Handle selection of relic slot to fill
C3A80B:  JSR C3A622      ; Queue text upload
         JSR C39650      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A841      ; Branch if not
         JSR C30F1D      ; Sound: Click
         LDA $4E         ; Cursor row
         STA $5F         ; Set body slot
         LDA #$5B        ; C3/A8A5
         STA $26         ; Next: Relic list
         JSR C3A85F      ; Get valid items
         JSR C3A95E      ; Sort by Defense
         JSR C3A2DA      ; Cursor & Scrollbar
         LDA #$5A        ; Return here if..
         STA $27         ; ..list is empty
         JSR C371A9      ; Clear BG1 map A
         JSR C313D3      ; Refresh screen
         JSR C3A49B      ; Draw item list
         JSR C39A1C      ; Draw stat preview
         JSR C3A631      ; Queue BG3 upload
         JMP C313D3      ; Refresh screen

; Fork: Handle B
C3A841:  LDA $09         ; Pushing B?
         BPL C3A855      ; Branch if not
         JSR C39632      ; Load navig data
         JSR C3963B      ; Relocate cursor
         LDA #$59        ; C3/A6C6
         STA $26         ; Next: Option list
         JMP C30F14      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A855:  LDA #$79        ; Init cmd: C3/A68B
         JMP C32088      ; Handle L and R

; 5B: Handle relic browsing
C3A8A5:  JSR desc_on     ; Description: On
         JSR C3A622      ; Queue text upload
         JSR C3A2C2      ; Handle navigation
         JSR C39A1C      ; Draw stat preview
         JSR C3A9E6      ; Load description

; Fork: Handle A
C3A8B5:  LDA $08         ; Pushing A?
         BPL C3A8EA      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JSR C3A239      ; Actor's address
         LDA $0023,Y     ; Relic to unequip
         CMP #$FF        ; None?
         BEQ C3A8D3      ; Branch if so
         JSR C3A56C      ; Put in stock
C3A8D3:  JSR ldgear1     ; Chosen item
         STA $0023,Y     ; Equip on actor
         JSR C3A5A5      ; Reduce stock
         JSR C398DA      ; Draw info; status
         BRA C3A8F3      ; Exit list

; Fork: Handle B
C3A8EA:  LDA $09         ; Pushing B?
         BPL C3A917      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C3A8F3:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C3A476      ; Clear stat preview
         LDA #$C1        ; Top cursor: Off
         TRB $46         ; Scrollbar: Off
         REP #$20        ; 16-bit A
         LDA #$0100      ; BG1 H-Shift: 256
         STA $7E9BD0     ; Hide gear list
         JSR C3964A      ; Load navig data
         LDA $5F         ; Former position
         STA $4E         ; Set cursor row
         JSR C39653      ; Relocate cursor
         LDA #$5A        ; C3/A80B
         STA $26         ; Next: Slot list
C3A917:  RTS

; 5C: Handle relic removal
C3A918:  JSR C3A631      ; Queue BG3 upload
         JSR C39650      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3A940      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JSR C39BE1      ; Actor's address
         REP #$21        ; 16-bit A; C-
         TXA             ; Move it to A
         SEP #$20        ; 8-bit A
         ADC $4B         ; Add cursor slot
         TAX             ; Index sum
         LDA $23,X       ; Relic worn
         JSR C3A56C      ; Put in stock
         LDA #$FF        ; Empty item
         STA $23,X       ; Clear relic worn
         JSR C398DA      ; Draw info; status

; Fork: Handle B
C3A940:  LDA $09         ; Pushing B?
         BPL C3A954      ; Branch if not
         JSR C39632      ; Load navig data
         JSR C3963B      ; Relocate cursor
         LDA #$59        ; C3/A6C6
         STA $26         ; Next: Option list
         JMP C30F14      ; Sound: Cursor

; Fork: Handle L and R, prepare for menu reset
C3A954:  LDA #$7A        ; Init cmd: C3/A699
         JMP C32088      ; Handle L and R

; Sort compatible gear by power after loading power ratings
C3A95E:  LDX #$AC8D      ; 7E/AC8D
         STX $2181       ; Set WRAM LBs
         LDA $7E9D89     ; List size
         CMP #$02        ; 0 or 1 item?
         BCC C3A917      ; Exit if so
         STA $E7         ; Memorize it
         STZ $E8         ; Clear HB
         TDC             ; Clear A
         TAX             ; Gear slot: 1
C3A975:  LDA $7E9D8A,X   ; Inventory slot
         PHX             ; Save gear slot
         TAY             ; Index former
         LDA $1869,Y     ; Item in slot
         JSR C38AA2      ; Compute index
         LDA $D85014,X   ; Item's power
         STA $2180       ; Add to list
         TDC             ; Clear A
         PLX             ; Gear slot
         INX             ; Gear slot +1
         CPX $E7         ; End of list?
         BNE C3A975      ; Loop if not

; Fork: Sort list of compatible gear by power
C3A995:  DEC $E7         ; List size -1
         PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAY             ; Items done: 0
C3A99E:  TDC             ; Clear A
         TAX             ; List slot: 1
C3A9A0:  LDA $AC8D,X     ; Item's power
         CMP $AC8E,X     ; Next is worse?
         BCS C3A9C5      ; Skip if not
         PHA             ; Memorize it
         LDA $9D8A,X     ; Item number A
         PHA             ; Memorize it
         LDA $AC8E,X     ; Item power B
         STA $AC8D,X     ; Replace A's
         LDA $9D8B,X     ; Item number B
         STA $9D8A,X     ; Replace A's
         PLA             ; Item number A
         STA $9D8B,X     ; Replace B's
         PLA             ; Item power A
         STA $AC8E,X     ; Replace B's
C3A9C5:  INX             ; List slot +1
         CPX $E7         ; End of list?
         BNE C3A9A0      ; Loop if not
         INY             ; Items done +1
         CPY $E7         ; Fully sorted?
         BNE C3A99E      ; Loop if not
         PLB             ; Restore DB
         RTS

; Load item description for relic browsing
C3A9E6:  JSR C38A89      ; Set desc ptrs
         JSR ldgear1     ; Item in slot
         JMP C35D95      ; Load description

; Establish button purposes and autofire delays
C3AC4F:  LDA #$08        ; Initial delay
         STA $0229       ; For: General
         LDA #$03        ; Repeat delay
         STA $022A       ; For: General
         STA $0226       ; For: A in battle
         LDA #$20        ; Initial delay
         STA $0225       ; For: A in battle
         LDA $1D54       ; Game options
         ASL A           ; Custom buttons?
         BPL C3AC6C      ; Reset if not
         JSR C3ADEF      ; Apply user keys
         RTL             ; Exit
C3AC6C:  JSR C3ADFC      ; Reset buttons
         RTL

; Decode joypads for battle
C3AC70:  LDA $1D54       ; Two players?
         BPL C3AC83      ; Branch if not
         TDC             ; Clear A
         LDA $0201       ; Member slot
         TAX             ; Index it
         LDA $1D4F       ; Assigned pad
         AND.L C3AD68,X  ; Player 2's?
         BNE C3AC88      ; Branch if so
C3AC83:  LDX $4218       ; Player 1 keys
         BRA C3AC8D      ; Skip a line
C3AC88:  LDX $421A       ; Player 2 keys
C3AC8D:  JSR C3ACAE      ; Decode keys
         JSR C3ACE8      ; Do autofire
         JSR C3AD21      ; Adjust it
         BRA C3AD52      ; Restore $E0+

; Decode joypads for field menu
C3AC99:  LDX $4218       ; Player 1 keys
         JSR C3ACAE      ; Decode keys
         JSR C3ACE8      ; Do autofire
         BRA C3AD52      ; Restore $E0+

; Decode joypads for field
C3ACA5:  LDX $4218       ; Player 1 keys
         JSR C3ACAE      ; Decode keys
C3AD52:  PLY             ; $EB backup
         STY $EB         ; Restore it
         PLY             ; $E9 backup
         STY $E9         ; Restore it
         PLY             ; $E7 backup
         STY $E7         ; Restore it
         PLY             ; $E0 backup
         STY $E0         ; Restore it
         TDC             ; Clear A
         RTL

; Update non-time-based joypad keys
C3ACAE:  PLY             ; Pull ret adr
         PEI ($E0)       ; Push temp var
         PEI ($E7)       ; Push temp var
         PEI ($E9)       ; Push temp var
         PEI ($EB)       ; Push temp var
         PHY             ; Push ret adr
         STX $EB         ; Save pad keys
         REP #$20        ; 16-bit A
         LDA $0C         ; Former keys
         AND #$FFF0      ; Unused bits...
         STA $E0         ; Memorize them
         JSR C3AD6C      ; Convert keys
         LDA $0C         ; Former keys
         EOR #$FFFF      ; Invert them
         AND $06         ; Keep current
         STA $08         ; Set no-auto keys
         LDY $06         ; Pushed keys
         STY $0C         ; Set former keys
         LDA $4218       ; Player 1 keys
         ORA $421A       ; Add player 2's
         STA $04         ; Set merged keys
         SEP #$20        ; 8-bit A
         RTS

; Update slow autofire keys
C3ACE8:  REP #$20        ; 16-bit A
         LDA $06         ; Pushed keys
         AND #$FFF0      ; Clear pad type
         CMP $E0         ; Unchanged?
         SEP #$20        ; 8-bit A
         BNE C3AD10      ; Use new if not
         LDA $0227       ; Initial delay
         BEQ C3ACFF      ; Branch if over
         DEC $0227       ; Initial delay -1
         BNE C3AD1C      ; No keys if > 0
C3ACFF:  DEC $0228       ; Repeat delay -1
         BNE C3AD1C      ; No keys if > 0
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
         LDY $06         ; Pushed keys
         STY $0A         ; Set slow keys
         RTS             ; Exit
C3AD10:  LDA $0229       ; Delay: 8
         STA $0227       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0228       ; Set repeat timer
C3AD1C:  LDY $08         ; No-autofire keys
         STY $0A         ; Set slow keys
C3AD20:  RTS

; Adjust slow autofire keys for battle
C3AD21:  LDA $06         ; Pushing A?
         BPL C3AD42      ; Branch if not
         LDA $0225       ; Initial delay
         BEQ C3AD31      ; Branch if over
         DEC $0225       ; Initial delay -1
         BNE C3AD4D      ; New keys if > 0
C3AD31:  DEC $0226       ; Repeat delay -1
         BNE C3AD4D      ; New keys if > 0
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
         LDA #$80        ; Button: A
         TSB $0A         ; Add to slow keys
         RTS             ; Exit
C3AD42:  LDA #$20        ; Delay: 32
         STA $0225       ; Set initial
         LDA $022A       ; Delay: 3
         STA $0226       ; Set repeat timer
C3AD4D:  LDA $08         ; No-autofire keys
         STA $0A         ; Set slow keys
C3AD51:  RTS

; Bitfield for joypad assignments
C3AD68:  db $01          ; Member 1
         db $02          ; Member 2
         db $04          ; Member 3
         db $08          ; Member 4

; Convert pushed keys based on user settings
C3AD6C:  LDA $EB         ; Pushed keys
         AND #$0F00      ; Get D-Pad's
         STA $06         ; Set fast keys
         LDA #$0080      ; Target: A
         STA $E7         ; Set key #1
         LDA #$8000      ; Target: B
         STA $E9         ; Set key #2
         LDY $00         ; Cfg index: 0
         JSR C3ADAC      ; Do A and B
         LDA #$0040      ; Target: X
         STA $E7         ; Set key #1
         LDA #$4000      ; Target: Y
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3ADAC      ; Do X and Y
         LDA #$0020      ; Target: L
         STA $E7         ; Set key #1
         LDA #$0010      ; Target: R
         STA $E9         ; Set key #2
         INY             ; Index +1
         JSR C3ADAC      ; Do L and R
         LDA #$1000      ; Target: Start
         STA $E7         ; Set key #1
         LDA #$2000      ; Target: Select
         STA $E9         ; Set key #2
         INY             ; Index +1

; Convert two pushed keys to their respective purposes
C3ADAC:  LDA $EB         ; Pushed keys
         BIT $E7         ; Has key #1?
         BEQ C3ADC6      ; Skip if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$F0        ; Get key #1's
         REP #$20        ; 16-bit A
         LSR A           ; Put in b3-b6
         LSR A           ; Put in b2-b5
         LSR A           ; Put in b1-b4
         TAX             ; Index it
         LDA.L C3ADDF,X  ; Action bit
         TSB $06         ; Set fast key
C3ADC6:  LDA $EB         ; Pushed keys
         BIT $E9         ; Has key #2?
         BEQ C3ADDE      ; Exit if not
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0220,Y     ; Key actions
         AND #$0F        ; Get key #2's
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3ADDF,X  ; Action bit
         TSB $06         ; Set fast key
C3ADDE:  RTS

; Bitfield for button purposes
C3ADDF:  dw $1000        ; End        (Start)
         dw $0080        ; Confirm    (A)
         dw $8000        ; Cancel     (B)
         dw $0040        ; Menu       (X)
         dw $4000        ; Switch     (Y)
         dw $0020        ; Page up    (L)
         dw $0010        ; Page down  (R, Select)
;        dw $2000        ; Unused

; Apply player's button settings
C3ADEF:  LDY $1D50       ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY $1D52       ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Apply default button settings
C3ADFC:  LDY #$3412      ; A, B, X, Y
         STY $0220       ; Set purposes
         LDY #$0656      ; L, R, Select
         STY $0222       ; Set purposes
         RTS

; Build tilemap for SwdTech list
C3AE09:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDX $00         ; ROM index: 0
C3AE14:  REP #$20        ; 16-bit A
         LDA.L C3AE3A,X  ; End of range
         STA $E7         ; Set row's limit
         INX             ; ROM index +1
         INX             ; ROM index +1
         LDA.L C3AE3A,X  ; Start of range
         TAY             ; Put in Y
         INX             ; ROM index +1
         INX             ; ROM index +1
         LDA.L C3AE3A,X  ; Base attributes
         INX             ; ROM index +1
         INX             ; ROM index +1
         PHX             ; Save ROM index
         TAX             ; Put attribs in X
         JSR C3B0C6      ; Build row
         PLX             ; ROM index
         CPX #$0060      ; End of table?
         BNE C3AE14      ; Loop if not
         RTS

; Tilemap data for Dispatch in SwdTech menu
C3AE3A:  dw $039C,$038A  ; Range: 6,15 to 14,15
         dw $3580        ; Tile 384, pal 5, priority
         dw $03DC,$03CA  ; Range: 6,16 to 14,16
         dw $3581        ; Tile 385, pal 5, priority

; Tilemap data for Retort in SwdTech menu
C3AE46:  dw $03B8,$03A6  ; Range: 20,15 to 28,15
         dw $3592        ; Tile 402, pal 5, priority
         dw $03F8,$03E6  ; Range: 20,16 to 28,16
         dw $3593        ; Tile 403, pal 5, priority

; Tilemap data for Slash in SwdTech menu
C3AE52:  dw $045C,$044A  ; Range: 6,18 to 14,18
         dw $35A4        ; Tile 420, pal 5, priority
         dw $049C,$048A  ; Range: 6,19 to 14,19
         dw $35A5        ; Tile 421, pal 5, priority

; Tilemap data for Quadra Slam in SwdTech menu
C3AE5E:  dw $0478,$0466  ; Range: 20,18 to 28,18
         dw $35B6        ; Tile 438, pal 5, priority
         dw $04B8,$04A6  ; Range: 20,19 to 28,19
         dw $35B7        ; Tile 439, pal 5, priority

; Tilemap data for Empowerer in SwdTech menu
C3AE6A:  dw $051C,$050A  ; Range: 6,21 to 14,21
         dw $35C8        ; Tile 456, pal 5, priority
         dw $055C,$054A  ; Range: 6,22 to 14,22
         dw $35C9        ; Tile 457, pal 5, priority

; Tilemap data for Stunner in SwdTech menu
C3AE76:  dw $0538,$0526  ; Range: 20,21 to 28,21
         dw $35DA        ; Tile 474, pal 5, priority
         dw $0578,$0566  ; Range: 20,22 to 28,22
         dw $35DB        ; Tile 475, pal 5, priority

; Tilemap data for Quadra Slice in SwdTech menu
C3AE82:  dw $05DC,$05CA  ; Range: 6,24 to 14,24
         dw $35EC        ; Tile 492, pal 5, priority
         dw $061C,$060A  ; Range: 6,25 to 14,25
         dw $35ED        ; Tile 493, pal 5, priority

; Tilemap data for Cleave in SwdTech menu
C3AE8E:  dw $05F8,$05E6  ; Range: 20,24 to 28,24
         dw $35FE        ; Tile 510, pal 5, priority
         dw $0638,$0626  ; Range: 20,25 to 28,25
         dw $35FF        ; Tile 511, pal 5, priority

; Load and upload VWF name graphics for every known SwdTech
C3AE9A:  LDX $00         ; Src: 7E/1CF8
         LDA #$01        ; Dispatch bit
         JSR C3AF24      ; Load name GFX
         LDY #$6C00      ; VRAM: $6C00
         JSR C3AF53      ; Upload GFX
         LDX #$0006      ; Src: 7E/1CFE
         LDA #$02        ; Retort bit
         JSR C3AF24      ; Load name GFX
         LDY #$6C90      ; VRAM: $6C90
         JSR C3AF53      ; Upload GFX
         LDX #$000C      ; Src: 7E/1D04
         LDA #$04        ; Slash bit
         JSR C3AF24      ; Load name GFX
         LDY #$6D20      ; VRAM: $6D20
         JSR C3AF53      ; Upload GFX
         LDX #$0012      ; Src: 7E/1D0A
         LDA #$08        ; Quadra Slam
         JSR C3AF24      ; Load name GFX
         LDY #$6DB0      ; VRAM: $6DB0
         JSR C3AF53      ; Upload GFX
         LDX #$0018      ; Src: 7E/1D10
         LDA #$10        ; Empowerer bit
         JSR C3AF24      ; Load name GFX
         LDY #$6E40      ; VRAM: $6E40
         JSR C3AF53      ; Upload GFX
         LDX #$001E      ; Src: 7E/1D16
         LDA #$20        ; Stunner bit
         JSR C3AF24      ; Load name GFX
         LDY #$6ED0      ; VRAM: $6ED0
         JSR C3AF53      ; Upload GFX
         LDX #$0024      ; Src: 7E/1D1C
         LDA #$40        ; Quadra Slice
         JSR C3AF24      ; Load name GFX
         LDY #$6F60      ; VRAM: $6F60
         JSR C3AF53      ; Upload GFX
         LDX #$002A      ; Src: 7E/1D22
         LDA #$80        ; Cleaver bit
         JSR C3AF24      ; Load name GFX
         LDY #$6FF0      ; VRAM: $6FF0
         JSR C3AF53      ; Upload GFX
         JMP C30FF4      ; Dequeue upload

; Load VWF name graphics for current SwdTech, unfreeze CGRAM
C3AF24:  STA $E0         ; Save SwdTech
         PHX             ; Save char index
         LDY #$0240      ; Tiles: 36
         JSR clr_vwf     ; Clear GFX buffer
         PLX             ; Character index
         LDA $1CF7       ; Known SwdTechs
         AND $E0         ; Includes ours?
         BEQ C3AF4E      ; Exit if not
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA #$06        ; Letters: 6
         STA $F1         ; Set counter
C3AF3C:  LDA $1CF8,X     ; Name letter
         LDY #$3F40      ; Base: C4/D400
         STY $EB         ; Set font index
         JSR C3B227      ; Load graphics
         INX             ; Char index +1
         DEC $F1         ; One less char
         BNE C3AF3C      ; Loop till last
C3AF4E:  LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         RTS

; Upload VWF graphics for element or SwdTech menu kanji; freeze CGRAM
C3AF53:  JSR C3AF5D      ; Set src and dst
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JMP C31517      ; Upload graphics

; Set to upload VWF string graphics (elements, SwdTech, ending pseudonym)
C3AF5D:  STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0120      ; Bytes: 288
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         RTS

; Build tilemap for actor's pseudonym in ending
C3AF6E:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$05A6      ; Ends at 19,23
         STY $E7         ; Set row's limit
         LDY #$059A      ; Starts at 14,23
         LDX #$2410      ; Tile 16, pal 1
         JSR C3B0C6      ; Build row 1
         LDY #$05E6      ; Ends at 19,24
         STY $E7         ; Set row's limit
         LDY #$05DA      ; Starts at 14,24
         LDX #$2411      ; Tile 17, pal 1
         JMP C3B0C6      ; Build row 2

; Load and set to upload VWF graphics for actor's pseudonym
C3AF98:  LDY #$0240      ; Tiles: 36
         JSR clr_vwf     ; Clear GFX buffer
         LDA #$08        ; Pixels: 8
         STA $B6         ; Set char width
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA #$06        ; Letters: 6
         STA $F1         ; Set counter
         LDX $00         ; Letter index: 0
C3AFAB:  LDA $7E9E89,X   ; Letter
         LDY #$5540      ; Base: C4/EA00
         STY $EB         ; Set font index
         JSR C3B227      ; Load graphics
         INX             ; Letter index +1
         DEC $F1         ; One less letter
         BNE C3AFAB      ; Loop till last
         LDY #$2080      ; VRAM pointer
         BRA C3AF5D      ; Queue upload

; Build description tilemap for Skills submenus
C3AFC5:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDY #$00BC      ; Ends at 30,3
         STY $E7         ; Set row's limit
         LDY #$0094      ; Starts at 11,3
         LDX #$3500      ; Tile 256, pal 5
         JSR C3B0C6      ; Build row 1
         LDY #$00FC      ; Ends at 30,4
         STY $E7         ; Set row's limit
         LDY #$00D4      ; Starts at 11,4
         LDX #$3501      ; Tile 257, pal 5
         JMP C3B0C6      ; Build row 2

; Build description tilemap for Relic menu
C3AFEE:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         JSR C3B0C6      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         JSR C3B0C6      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         JSR C3B0C6      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
         BRA C3B0C6      ; Do line 2, row 2

; Build description tilemap for shop menu
C3B037:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$04BC      ; Ends at 30,19
         STY $E7         ; Set row's limit
         LDY #$0484      ; Starts at 3,19
         LDX #$3500      ; Tile 256, pal 5
         JSR C3B0C6      ; Do line 1, row 1
         LDY #$04FC      ; Ends at 30,20
         STY $E7         ; Set row's limit
         LDY #$04C4      ; Starts at 3,20
         LDX #$3501      ; Tile 257, pal 5
         JSR C3B0C6      ; Do line 1, row 2
         LDY #$053C      ; Ends at 30,21
         STY $E7         ; Set row's limit
         LDY #$0504      ; Starts at 3,21
         LDX #$3538      ; Tile 312, pal 5
         JSR C3B0C6      ; Do line 2, row 1
         LDY #$057C      ; Ends at 30,22
         STY $E7         ; Set row's limit
         LDY #$0544      ; Starts at 3,22
         LDX #$3539      ; Tile 313, pal 5
         BRA C3B0C6      ; Do line 2, row 2

; Build description tilemap for Item or Colosseum menu
C3B080:  LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDY #$01BC      ; Ends at 30,7
         STY $E7         ; Set row's limit
         LDY #$0184      ; Starts at 3,7
         LDX #$3500      ; Tile 256, pal 5
         JSR C3B0C6      ; Do line 1, row 1
         LDY #$01FC      ; Ends at 30,8
         STY $E7         ; Set row's limit
         LDY #$01C4      ; Starts at 3,8
         LDX #$3501      ; Tile 257, pal 5
         JSR C3B0C6      ; Do line 1, row 2
         LDY #$023C      ; Ends at 30,9
         STY $E7         ; Set row's limit
         LDY #$0204      ; Starts at 3,9
         LDX #$3538      ; Tile 312, pal 5
         JSR C3B0C6      ; Do line 2, row 1
         LDY #$027C      ; Ends at 30,10
         STY $E7         ; Set row's limit
         LDY #$0244      ; Starts at 3,10
         LDX #$3539      ; Tile 313, pal 5
C3B0C6:  SEP #$20        ; 8-bit A
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         REP #$20        ; 16-bit A
C3B0C8:  TXA             ; Tile attributes
         STA [$EB],Y     ; Put in tilemap
         INX             ; Tile +1
         INX             ; Tile +1
         INY             ; Index +1
         INY             ; Index +1
         CPY $E7         ; Beyond range?
         BNE C3B0C8      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Clear buffer for VWF description graphics
C3B0D9:  LDY #$0700      ; Bytes: 1792
         JMP clr_vwf     ; Clear buffer

; Update VWF description
C3B151:  CMP #$02        ; Mode 1?
         BEQ C3B172      ; Branch if so
         BCS C3B15E      ; If mode 2

; Mode 0: Clear description
C3B15B:  JSR C3B0D9      ; Clear desc GFX

; Mode 2: Initialize variables
C3B15E:  STZ $8D         ; Line width: 0
         LDX $2D         ; Queue index
         LDA #$01        ; Mode: 1
         STA $3649,X     ; Next: Update
         REP #$20        ; 16-bit A
         STZ $33CA,X     ; Char index: 0
         STZ $344A,X     ; VRAM index: 0
         SEP #$20        ; 8-bit A

; Mode 1: Sustain description
C3B172:  LDA $26         ; Menu mode
         CMP #$17        ; Item menu top?
         BEQ C3B1D0      ; Blank if so
         LDA $46         ; Menu flags
         AND #$C0        ; No scrollbar?
         BEQ C3B184      ; Branch if so
         LDA $06         ; Pushed keys
         AND #$30        ; Using L or R?
         BNE C3B1D8      ; Reset if so
C3B184:  LDA $45         ; Menu flags
         BIT #$20        ; Ignore D-Pad?
         BNE C3B190      ; Branch if so
         LDA $07         ; Pushed keys
         AND #$0F        ; Using D-Pad?
         BNE C3B1D8      ; Reset if so
C3B190:  LDA $45         ; Menu flags
         BIT #$10        ; Clear desc?
         BNE C3B1D8      ; Reset if so
         TXY             ; Queue index
         LDX $344A,Y     ; VRAM index
         STX $ED         ; Memorize it
         LDX $33CA,Y     ; Char index

; Fork: Handle line break
C3B1A0:  LDA $7E9EC9,X   ; Text character
         BEQ C3B1DF      ; Branch if <end>
         CMP #$01        ; Line break?
         BNE C3B1B8      ; Branch if not
         STZ $8D         ; Line width: 0
         REP #$20        ; 16-bit A
         LDA #$0380      ; Base tile: 57
         STA $344A,Y     ; Set VRAM index
         BRA C3B1C0      ; Queue upload

; Fork: Handle character
C3B1B8:  JSR C3B1EC      ; Decode char
         JSR C3B227      ; Load graphics

; Fork: Queue upload, advance char index
C3B1C0:  INX             ; Char index +1
         LDY $2D         ; Queue index
         REP #$20        ; 16-bit A
         TXA             ; Char index
         STA $33CA,Y     ; Put in queue
         SEP #$20        ; 8-bit A
         JSR C3B301      ; Queue upload
         SEC             ; Set to requeue
         RTS

; Fork: Clear description, stop updating
C3B1D0:  JSR C3B0D9      ; Clear desc GFX
         JSR C3B301      ; Set to upload
         CLC             ; Set to dequeue
         RTS

; Fork: Set to reset description
C3B1D8:  LDX $2D         ; Queue index
         STZ $3649,X     ; Mode: 0
         SEC             ; Set to requeue
         RTS

; Fork: Handle terminator
C3B1DF:  LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         LDX $2D         ; Queue index
         LDA #$02        ; Mode: 2
         STA $3649,X     ; Next: Init
         SEC             ; Set to requeue
         RTS

; Decode character from VWF string
C3B1EC:  CMP #$1C        ; Control 1C?
         BEQ C3B205      ; Branch if so
         CMP #$1D        ; Control 1D?
         BEQ C3B20C      ; Branch if so
         CMP #$1E        ; Control 1E?
         BEQ C3B213      ; Branch if so
         CMP #$1F        ; Control 1F?
         BEQ C3B21A      ; Branch if so

; Fork: Kana, etc. (large version)
C3B1FC:  SEC             ; Prepare SBC
         SBC #$20        ; Make 0-based
         STZ $EB         ; Font index LB: 0
         STZ $EC         ; Font index HB: 0
         RTS

; Fork: Kanji table A
C3B205:  LDY #$1340      ; Base: C4/A800
         STY $EB         ; Set font index
         BRA C3B221      ; Get true char

; Fork: Kanji table B
C3B20C:  LDY #$2940      ; Base: C4/BE00
         STY $EB         ; Set font index
         BRA C3B221      ; Get true char

; Fork: Kanji table C
C3B213:  LDY #$3F40      ; Base: C4/D400
         STY $EB         ; Set font index
         BRA C3B221      ; Get true char

; Fork: Kanji table D and smaller kana, etc.
C3B21A:  LDY #$5540      ; Base: C4/EA00
         STY $EB         ; Set font index
C3B221:  INX             ; Char index +1
         LDA $7E9EC9,X   ; Get true char
C3B226:  RTS

; Load VWF character's graphics into string, add shadow effect
C3B227:  PHX             ; Save X
         XBA             ; Put char in B
         LDA #$16        ; GFX data size
         JSR mul8        ; Char x size
         REP #$21        ; 16-bit A; C-
         ADC $EB         ; Add font index
         TAY             ; Set ROM index
         SEP #$20        ; 8-bit A
         LDA #$0B        ; Rows left: 11
         STA $E5         ; Set counter
         TDC             ; Clear A
         LDA $8D         ; Textline width
         AND #$F8        ; Drop WIP tile's
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         CLC             ; Prepare ADC
         ADC $ED         ; Add VRAM index
         TAX             ; Set RAM index

; Fork: Load 1bpp row graphics, shift to fit string
C3B24F:  PHX             ; Save RAM index
         REP #$20        ; 16-bit A
         TYX             ; ROM index
         LDA $C494C0,X   ; 12-px row GFX
         STZ $E7         ; Blank slice C
         STZ $E9         ; Clear byte 4
         STA $E8         ; Set slices A+B
         JSR C3B2BF      ; Shift pixels

; Fork: Insert row segment C, copy as shadow below (2bpp)
C3B260:  PLX             ; RAM index
         LDA $E7         ; Slices B and C
         SEP #$20        ; 8-bit A
         ORA $7EA2B9,X   ; Add WIP plane A
         STA $7EA2B9,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA2BC,X   ; Add WIP plane B
         STA $7EA2BC,X   ; Set WIP plane B

; Fork: Insert row segment B, copy as shadow below (2bpp)
C3B27A:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         ORA $7EA299,X   ; Add WIP plane A
         STA $7EA299,X   ; Set WIP plane A
         REP #$20        ; 16-bit A
         LSR A           ; Shift 1 px right
         SEP #$20        ; 8-bit A
         ORA $7EA29C,X   ; Add WIP plane B
         STA $7EA29C,X   ; Set WIP plane B

; Fork: Insert row segment A, copy as shadow below (2bpp)
C3B295:  REP #$20        ; 16-bit A
         LDA $E8         ; Slices A and B
         SEP #$20        ; 8-bit A
         XBA             ; Get slice A
         ORA $7EA279,X   ; Add WIP plane A
         STA $7EA279,X   ; Set WIP plane A
         LSR A           ; Shift 1 px right
         ORA $7EA27C,X   ; Add WIP plane B
         STA $7EA27C,X   ; Set WIP plane B

; Fork: Handle next row
C3B2AD:  INX             ; RAM index +1
         INX             ; RAM index +1
         INY             ; ROM index +1
         INY             ; ROM index +1
         DEC $E5         ; One less row
         BNE C3B24F      ; Loop till last

; Fork: Add character's width to line total
C3B2B5:  TDC             ; Clear A
         LDA $8D         ; Line width
         CLC             ; Prepare ADC
         ADC $B6         ; Add char width
         STA $8D         ; Save changes
         PLX             ; Restore X
         RTS

; Shift VWF character's row for string insertion
C3B2BF:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $8D         ; Line width
         AND #$07        ; WIP tile's
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         JMP (C3B2CD,X)  ; Shift row

; Jump table for the above
C3B2CD:  dw C3B2DF       ; 0: 4 px left
         dw C3B2E3       ; 1: 3 px left
         dw C3B2E7       ; 2: 2 px left
         dw C3B2EB       ; 3: 1 px left
         dw C3B2EF       ; 4: Unchanged
         dw C3B2FC       ; 5: 1 px right
         dw C3B2F8       ; 6: 2 px right
         dw C3B2F4       ; 7: 3 px right
;        dw C3B2F0       ; 8: 4 px right (unused)

; Shift VWF character's row left for string insertion
C3B2DF:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3B2E3:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3B2E7:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3B2EB:  ASL $E7         ; Do slice B+C
         ROL $E9         ; Do slice A
C3B2EF:  RTS

; Shift VWF character's row right for string insertion
C3B2F0:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3B2F4:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3B2F8:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
C3B2FC:  LSR $E9         ; Do slice A
         ROR $E7         ; Do slice B+C
         RTS

; Set to upload VWF description, freeze CGRAM
C3B301:  LDY #$6800      ; $6800
         STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0700      ; Bytes: 1792
         STY $19         ; Set data size
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         RTS

; Load and upload VWF graphics for all elements
C3B319:  LDX $00         ; Elem index: 0
C3B31B:  LDA $D8E990,X   ; Elem text char
         STA $7E9EC9,X   ; Memorize it
         INX             ; Elem index +1
         CPX #$0011      ; Terminator?
         BNE C3B31B      ; Loop if not
         LDY #$6C00      ; $6C00
         STY $F1         ; Set VRAM ptr
         TDC             ; Clear A
         TAX             ; Elem index: 0
C3B330:  LDA $7E9EC9,X   ; Elem text char
         BEQ C3B352      ; Exit if none
         JSR C3B1EC      ; Decode char
         PHX             ; Save index
         JSR C3B355      ; Load graphics
         PLX             ; Elem index
         INX             ; Elem index +1
         LDY $F1         ; VRAM pointer
         JSR C3AF53      ; Upload graphics
         REP #$21        ; 16-bit A; C-
         LDA $F1         ; VRAM pointer
         ADC #$0020      ; Skip 4 tiles
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         BRA C3B330      ; Do next element
C3B352:  JMP C30FF4      ; Dequeue upload

; Load element's graphics (VWF)
C3B355:  PHA             ; Save text char
         LDY #$0040      ; Bytes: 64
         JSR clr_vwf     ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         PLA             ; Elem text char
         JMP C3B227      ; Load graphics

; 73: Initialize final battle lineup
C3B368:  JSR C335F7      ; Reset/Stop stuff
         JSR C37076      ; Reset BGs' X/Y
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDY #C3B5D3     ; C3/B5D3
         JSR C30681      ; Load navig data
         JSR C3B5CD      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C3B45E      ; Clear candidates
         JSR C3B46D      ; Reset user's list
         JSR C3B483      ; Draw menu
         JSR C39C86      ; Set to shift text
         LDA #$74        ; C3/B395
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JSR C30F68      ; Queue text upload
         JMP C33609      ; BRT:1 + NMI

; 74: Sustain final battle lineup
C3B395:  JSR C3B4F9      ; Redraw candidates
         JSR C3B524      ; Redraw user's list
         JSR C3B5CA      ; Handle D-Pad
         JSR C30F68      ; Queue text upload

; Fork: Handle B
C3B3A1:  LDA $09         ; Pushing B?
         BPL C3B3D3      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         LDA $4A         ; R-List's empty?
         BEQ C3B421      ; Exit if so
         DEC $4A         ; R-List size -1
         TDC             ; Clear A
         LDA $4A         ; R-List size
         TAX             ; Index it
         LDA $0205,X     ; Last R-List char
         PHA             ; Save this actor
         LDA #$FF        ; Actor: None
         STA $0205,X     ; Clear R-List slot
         LDX #$000B      ; L-List slot: 12
         PLA             ; Removed actor
C3B3C0:  CMP $7E9D8A,X   ; In L-List slot?
         BEQ C3B3CC      ; Enable it if so
         DEX             ; L-List slot -1
         BPL C3B3C0      ; Loop till < 0
C3B3CC:  LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set L-List name's
         RTS

; Fork: Handle actor selection
C3B3D3:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C3B409      ; Branch if so
         LDA $08         ; Pushing A?
         BPL C3B421      ; Exit if not
         JSR C30F1D      ; Sound: Click
         TDC             ; Clear A
         LDA $4B         ; On Reset?
         BEQ C3B417      ; Branch if so
         CMP #$0D        ; On "End"?
         BEQ C3B409      ; Branch if so
         TAX             ; Clicked slot
         LDA $7E9D89,X   ; Nobody there?
         BMI C3B421      ; Exit if so
         LDA $4B         ; Clicked slot
         TAX             ; Index it
         LDA $7EAA8D-1,X ; Name color
         CMP #$20        ; Player's?
         BNE C3B421      ; Exit if not
         JSR C3B422      ; Add chosen char
         LDA $4A         ; Selection count
         CMP #$0C        ; Added 12 actors?
         BNE C3B421      ; Exit if not

; Fork: Put cursor on "End"
C3B41D:  LDA #$0D        ; Row: 14th
         STA $4E         ; Set cursor's
C3B421:  RTS

; Fork: Handle "End"
C3B409:  JSR C3B43A      ; Auto-fill list
         JSR fdexit      ; Queue menu exit
         JMP C30F1D      ; Sound: Click

; Fork: Handle "Reset"
C3B417:  INC $4E         ; Move cursor down
         BRA C3B46D      ; Reset user's list

; Add chosen actor to player's list for final battle
C3B422:  TDC             ; ...
         LDA $4A         ; Slot to fill
         TAY             ; Index it
         JSR C3CF1D      ; Chosen actor
         STA $0205,Y     ; To user's list
         INC $4A         ; R-List size +1
         LDA #$28        ; Color: Gray
         STA $7EAA8C,X   ; Set L-Name's
         RTS

; Complete player's actor list for final battle
C3B43A:  LDA $4A         ; R-List size
         CMP #$0C        ; 12 actors?
         BEQ C3B45D      ; Exit if so
         TDC             ; Clear A
         TAX             ; L-List slot: 1
C3B442:  LDA $7EAA8D,X   ; Name color
         CMP #$20        ; Player's?
         BNE C3B457      ; Skip if not
;        TDC             ; Clear A
         LDA $4A         ; R-List slot
         TAY             ; Index it
         LDA $7E9D8A,X   ; L-List actor
         STA $0205,Y     ; Add to list
         INC $4A         ; R-List slot +1
C3B457:  INX             ; L-List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3B442      ; Loop if not
C3B45D:  RTS

; Clear candidate list for final battle (four unused slots)
C3B45E:  LDX #$000F      ; List slot: 16
         LDA #$FF        ; Actor: None
.loop    STA $7E9D89,X   ; Clear slot
         DEX             ; List slot -1
         BPL .loop       ; Loop till < 0
         RTS

; Reset player's actor list for final battle
C3B46D:  LDX #$000B      ; List slot: 12
C3B46F:  LDA #$FF        ; Actor: None
         STA $0205,X     ; Put in slot
         LDA #$20        ; Color: User's
         STA $7EAA8D,X   ; Set name color
         DEX             ; List slot -1
         BPL C3B46F      ; Loop till < 0
         STZ $4A         ; List size: 0
         RTS

; Draw menu for final battle
C3B483:  LDA #$02        ; 32x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3B4B9     ; C3/B4B9
         JSR C303C4      ; Draw window
         JSR C30EBD      ; Upload window
         JSR C371D0      ; Clear BG3 map A
         JSR C30ED9      ; Upload BG3 A+B
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C3D24D      ; Color: User's
         LDX #C3B5F4     ; Text ptrs loc
         LDA #$03        ; Strings: 3
         JSR C3714E      ; Draw End, etc.
         JSR C3B589      ; Draw numbers
         JSR C3B4BD      ; List candidates
         JSR C3B4F9      ; Draw candidates
         JMP C30E93      ; Upload text

; Compile candidates for final battle
C3B4BD:  TDC             ; Clear A
         TAY             ; List slot: 1
         TAX             ; 1st: Terra
C3B4C1:  PHX             ; Save actor
         LDA $1850,X     ; Party info
         ASL A           ; Object's off?
         BPL C3B4F1      ; Skip if so
         AND #$0E        ; In a party?
         BEQ C3B4F1      ; Skip if not
         STX $E7         ; Save actor
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C370DB,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $00,X       ; Actor in slot
         CMP #$0E        ; Guest?
         BCS C3B4F1      ; Skip if so
         TYX             ; List slot
         LDA $E7         ; Actor slot
         STA $7E9D8A,X   ; Add to list
         INY             ; List slot +1
C3B4F1:  PLX             ; Actor slot
         INX             ; Actor slot +1
         CPX #$0010      ; Done all 16?
         BNE C3B4C1      ; Loop if not
         RTS

; Draw list of candidates for final battle
C3B4F9:  LDY #$39D5      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3B500:  LDY $F5         ; Tilemap ptr
         JSR C335E1      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $7EAA8D,X   ; Name palette
         STA $29         ; Set attributes
         LDA $7E9D8A,X   ; Actor in slot
         BMI C3B516      ; Blank if none
         JSR C3B560      ; Draw name
         BRA C3B519      ; Skip a line
C3B516:  JSR C3B57B      ; Blank slot
C3B519:  JSR C3B56E      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3B500      ; Loop if not
         RTS

; Draw player's actor list for final battle
C3B524:  JSR C3D24D      ; Color: User's
         LDY #$39F1      ; Tilemap ptr
         STY $F5         ; Set position
         TDC             ; Clear A
         TAX             ; List slot: 1
C3B52F:  LDY $F5         ; Tilemap ptr
         JSR C335E1      ; Set pos, WRAM
         PHX             ; Save list slot
         TDC             ; Clear A
         LDA $0205,X     ; Actor in slot
         BMI C3B53E      ; Blank if none
         JSR C3B560      ; Draw name
         BRA C3B541      ; Skip a line
C3B53E:  JSR C3B57B      ; Blank slot
C3B541:  JSR C3B56E      ; VRAM row +2
         PLX             ; List slot
         INX             ; List slot +1
         CPX #$000C      ; Done all 12?
         BNE C3B52F      ; Loop if not
         RTS

; Draw actor's name for final battle lineup
C3B560:  ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         JMP C3356D      ; Draw name

; Point two rows down in tilemap
C3B56E:  REP #$21        ; 16-bit A; C-
         LDA $F5         ; Tilemap ptr
         ADC #$0080      ; +2 rows down
         STA $F5         ; Save changes
         SEP #$20        ; 8-bit A
         RTS

; Blank actor name slot
C3B57B:  LDY #$0006      ; Spaces: 6
         JMP spacedr     ; Draw 6 spaces

; Draw both lists of numbers for final battle lineup
C3B589:  LDY #$3A0F      ; Tilemap ptr
         JSR C3B5AB      ; Draw left list
         LDY #$3A2B      ; Tilemap ptr
;        BRA C3B5AB      ; Draw right list

; Draw current list of numbers for final battle lineup
C3B5AB:  STY $F5         ; Set position
         LDA #$01        ; Number: "1"
C3B5AD:  PHA             ; Save number
         JSR C30563      ; Turn into text
         LDX $F5         ; Text position
         JSR C30539      ; Draw 2 digits
         JSR C3B56E      ; VRAM row +2
         PLA             ; Number
         INC A           ; Number +1
         CMP #$0D        ; Done all 12?
         BNE C3B5AD      ; Loop if not
C3B5C3:  RTS

; Handle D-Pad for final battle lineup
C3B5CA:  JSR C307B0      ; Handle D-Pad
C3B5CD:  LDY #C3B5D8     ; C3/B5D8
         JMP C306C3      ; Relocate cursor

; 71: Initialize Colosseum item menu
C3B619:  STZ $0201       ; Face Shadow: No
         JSR C31B48      ; Init list vars
         JSR C384AC      ; Relocate cursor
         JSR C3B696      ; Draw/Upload menu
         JSR C31B74      ; Shift & OBJ & Fade
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C313D3      ; Refresh screen
         LDA #$72        ; C3/B64B
         STA $27         ; Queue: Sustain menu
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C30833      ; Queue cursor OAM
         JMP C33609      ; BRT:1 + NMI

; 72: Sustain Colosseum item menu
C3B64B:  JSR desc_on     ; Description: On
         STZ $2A         ; List type: Stock
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C3B5C3      ; Exit if pushed
         JSR C384A9      ; Handle D-Pad
         JSR C38A72      ; Load description

; Fork: Handle A
C3B65F:  LDA $08         ; Pushing A?
         BPL C3B683      ; Branch if not
         JSR C3CF26      ; Selected item
         CMP #$FF        ; None?
         BEQ C3B67D      ; Fail if so
         STA $0205       ; Set item bet
         LDA #$75        ; C3/B724
         STA $27         ; Queue: Matchup
         STZ $26         ; Next: Fade-out
         JMP C30F1D      ; Sound: Click

; Fork: Invalid selection
C3B67D:  JSR C3C5C6      ; Buzzer + Mosaic

; Fork: Handle B
C3B683:  LDA $09         ; Pushing B?
         BPL C3B5C3      ; Exit if not
         LDA #$FF        ; Empty item
         STA $0205       ; Clear item bet
         JSR fdexit      ; Queue menu exit
         JMP C30F14      ; Sound: Cursor

; Draw and upload Colosseum item menu
C3B696:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3B6F9     ; C3/B6F9
         JSR boxes_      ; Upload windows
         JSR bg3d_cl     ; Clear BG3 maps
         JSR C3D252      ; Color: Blue
         LDY #C3B709     ; Text pointer
         JSR C30326      ; Draw "Colosseum"
         JSR C3D24D      ; Color: User's
         JSR C3B080      ; Build desc map
         LDY #C3B711     ; Text pointer
         JSR C30326      ; Draw "Select..."
         JSR up_bg3      ; Upload BG3 maps
         JSR C371AD      ; Clear BG1 map B
         JSR C385BC      ; Draw inventory
         JSR C38A72      ; Load description
         JMP C30E93      ; Upload BG1 A+B

; 75: Initialize Colosseum matchup menu
C3B724:  JSR C335F7      ; Reset/Stop stuff
         STZ $43         ; Disable HDMA
;        JSR C33B5B      ; Load skin visuals
;        JSR C37087      ; Get party info
         LDA #$02        ; Gradient set: 2
         JSL $D4CA1D     ; Create gradient
         JSR C37170      ; Queue Win1 HDMA
         JSR C371FA      ; Load GFX/pal/prize
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         LDY #C3BC9F     ; C3/BC9F
         JSR C30681      ; Load navig data
         JSR C3BC99      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDY #C3BC60     ; C3/BC60
         JSR qanim1      ; Queue "VS" OAM
         JSR C3193A      ; Set to shift text
         JSR C3B7A1      ; Draw menu; members
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C340B9      ; Apply user font
         LDY #C3BC12     ; C3/BC12
         JSR qanim1      ; Queue challenger fn
         LDA #$76        ; C3/B77C
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
;        JSR C37076      ; Reset BGs' X/Y
         JSR C30F68      ; Queue enemy upload
         JSR C33609      ; BRT:1 + NMI
         JMP C30FA4      ; Queue text upload

; 76: Sustain Colosseum matchup menu
C3B77C:  JSR C30FA4      ; Queue text upload
         JSR C3BC96      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3B813      ; Exit if not
         JSR C3BC59      ; Actor in slot
         BMI C3B79A      ; Fail if nobody
         STA $0208       ; Set challenger
         JSR fdexit      ; Queue menu exit
         JMP C30F1D      ; Sound: Click
C3B79A:  JMP C3C5C6      ; Buzzer + Mosaic

; Draw Colosseum matchup menu and create members
C3B7A1:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDX #C3BCAC     ; C3/BCAC
         JSR boxes_      ; Upload windows
         JSR C371D0      ; Clear BG3 map A
         JSR C3D24D      ; Color: User's
         JSR C3BAEA      ; Create member 1
         JSR C3BB04      ; Create member 2
         JSR C3BB1E      ; Create member 3
         JSR C3BB38      ; Create member 4
         LDY #C3BD7C     ; Text pointer
         JSR C30326      ; Draw "Select..."
         JSR C3BBFA      ; Draw enemy name
         JSR C3BBBA      ; Draw item bet
         JSR C3BBC2      ; Draw prize
         JSR C30ED9      ; Upload BG3 A+B
         LDY #$5000      ; $5000
         STY $2116       ; Set VRAM ptr
         JSR C3BA77      ; Blank BG1 tile 1
         JSR C371A9      ; Clear BG1 map A
         JSR C3B800      ; Handle Striker
         LDA $0201       ; Facing Shadow?
         BNE C3B7FA      ; Branch if so
         JSR C3B86D      ; Draw monster
         BRA C3B7F_      ; Upload BG1 A+B

; Fork: Fighting Shadow
C3B7FA:  JSR C3B814      ; Do name/sprite
C3B7F_:  JMP C30E93      ; Upload BG1 A+B

; Check if betting Striker
C3B800:  LDA $0205       ; Item bet
         CMP #$29        ; Striker?
         BNE C3B813      ; Exit if not
         LDA $1EBD       ; Shadow at arena?
         BPL C3B813      ; Exit if not
         LDA #$01        ; Facing Shadow: Y
         STA $0201       ; Set arena's mode
C3B813:  RTS

; Create Shadow's name and sprite for Colosseum
C3B814:  JSR C3B846      ; Draw "Shadow"
         LDA #$02        ; For C3/8316...
         TSB $47         ; See C3/BC28...
         LDY #C381F3     ; C3/81F3
         JSR qanim2      ; Queue OAM fn
         LDA #$01        ; OAM mode: 1
         STA $7E3649,X   ; Set sprite's
         LDA $7E364A,X   ; Sprite flags
         ORA #$02        ; Add H-Flip
         STA $7E364A,X   ; Save changes
         TXY             ; Queue index
         PEA $6838       ; Pos: 56, 104
         TDC             ; Clear A
         LDA #$03        ; Sprite set: 3
         JMP C3BB7E      ; Set pos/anim ptr

; Draw Shadow's name at Colosseum
C3B846:  LDX #$001E      ; 1st: Guest 2
C3B848:  REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP #$03        ; Shadow?
         BEQ C3B865      ; Retain if so
         DEX             ; Actor index -1
         DEX             ; Actor index -1
         BPL C3B848      ; Loop till < 0
         STP             ; Freeze game...
C3B865:  STY $67         ; Save actor index
         LDY #$7C11      ; Text position
         JMP C3356A      ; Draw actor name

; Build tilemap for Colosseum enemy
C3B86D:  LDX $91         ; Tilemap ptr
         STX $ED         ; Set dst LBs
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BEQ C3B883      ; Branch if so
         LDX #$0010      ; Tiles: 16
         STX $F1         ; Set height
         STX $E0         ; Set width
         BRA C3B88A      ; Skip 3 lines
C3B883:  LDX #$0008      ; Tiles: 8
         STX $F1         ; Set height
         STX $E0         ; Set width
C3B88A:  LDA #$7E        ; Bank: 7E
         STA $EF         ; Set dst HB
         REP #$20        ; 16-bit A
         LDA #$2C01      ; Tile 1, pal 3
         STA $E7         ; Priority: Yes
C3B895:  LDX $E0         ; Width in tiles
         LDY $00         ; Map index: 0
C3B899:  LDA $E7         ; Tile attribs
         STA [$ED],Y     ; Put in tilemap
         INY             ; Map index +1
         INY             ; Map index +1
         INC $E7         ; Tile number +1
         DEX             ; One less column
         BNE C3B899      ; Loop till last
         LDA $ED         ; Tilemap ptr
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $ED         ; Save changes
         DEC $F1         ; One less row
         BNE C3B895      ; Loop till last
         SEP #$20        ; 8-bit A
         RTS

; Load prize and enemy data for Colosseum matchup
C3B8B3:  JSR C3BB99      ; Set enemy, prize
         LDY #$5010      ; $5010
         STY $2116       ; Set VRAM ptr
         LDA $0206       ; Enemy number
         XBA             ; Put in B
         LDA #$05        ; Enemy data size
         JSR mul8        ; Enemy x size
         TAX             ; Index product
         LDA $D27000,X   ; GFX ptr/8 LSBs
         STA $E7         ; Save in RAM
         LDA $D27001,X   ; Ptr MSBs; flag
         STA $E8         ; Save in RAM
         LDA $D27002,X   ; Pal/Mold info
         STA $F2         ; Save in RAM
         LDA $D27003,X   ; Palette LSBs
         STA $F1         ; Save in RAM
         LDA $D27004,X   ; Mold index LSBs
         STA $E9         ; Save in RAM

; Fork: Relocate color depth flag
C3B8EA:  LDA $E8         ; 8-color palette?
         BMI C3B8F2      ; Branch if so
         STZ $FF         ; Colors: 16
         BRA C3B8FA      ; Skip other case
C3B8F2:  LDA #$01        ; Colors: 8
         STA $FF         ; Set color depth
         LDA #$80        ; 8-color flag
         TRB $E8         ; Clear original

; Fork: Compute enemy graphics address ($E97000+8X)
C3B8FA:  LDY $E7         ; GFX ptr / 8
         LDA #$08        ; Multiplier
         JSR mul16       ; GFX ptr x 8
;        LDA $2136       ; Product HB
         CLC             ; Prepare ADC
         ADC #$E9        ; Add base adr
         STA $F7         ; Set address HB
         REP #$21        ; 16-bit A; C-
         TXA             ; Product LBS
         ADC #$7000      ; Add base adr
         STA $F5         ; Set address LBs
         SEP #$20        ; 8-bit A
         BCC .skip       ; If no overflow
         INC $F7         ; Address HB +1
.skip    LDX $00         ; GFX index: 0

; Fork: Set address pointer and size for 8x8 mold data
C3B926:  LDA $F2         ; 16x16 image?
         BMI C3B935      ; Branch if so
         LDY #$A820      ; D2/A820
         STY $E3         ; Set address ptr
         LDA #$08        ; 8-tile rows: 8
         BRA C3B93C      ; Set data size

; Fork: Set address pointer and size for 16x16 mold data
C3B935:  LDY #$A822      ; D2/A822
         STY $E3         ; Set address ptr
         LDA #$20        ; 8-tile rows: 32
C3B93C:  STA $E6         ; Set rows left
         STA $99         ; Set enemy size
         LDA #$D2        ; Bank: D2
         STA $E5         ; Set pointer HB

; Fork: Define mold index's high byte
C3B944:  LDA $F2         ; Monster flags
         AND #$40        ; Mold index MSB
         ASL A           ; Put in bit 7
         ROL A           ; Put in Carry
         ROL A           ; Put in bit 0
         STA $EA         ; Set index HB

; Fork: Load address to 8x8 enemy's mold ($D2A824+8X)
C3B94D:  LDA $F2         ; 16x16 image?
         BMI C3B95A      ; Branch if so
         REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         ASL A           ; x2
         ASL A           ; x4
         ASL A           ; x8
         BRA C3B963      ; Set address

; Fork: Load address to 16x16 enemy's mold ($D2AC24+32X)
C3B95A:  REP #$20        ; 16-bit A
         LDA $E9         ; Mold index
         JSR x32         ; x32
C3B963:  CLC             ; Prepare ADC
         ADC [$E3]       ; Add base adr
         STA $E0         ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$D2        ; Bank: D2
         STA $E2         ; Set src HB

; Fork: Load 8-tile row, blank tiles excluded from mold
C3B96E:  LDY #$0008      ; Columns: 8
         PHX             ; Save GFX index
         TDC             ; Clear A
         LDA $E6         ; Rows left
         TAX             ; Index it
         LDA [$E0]       ; Mold row flags
         STA $7E9D88,X   ; For centering
         PLX             ; GFX index
C3B97D:  CLC             ; Prepare ROL
         PHY             ; Save column
         ROL A           ; Blank tile here?
         PHA             ; Save mold flags
         BCC C3B988      ; Branch if blank
         JSR C3BA8B      ; Load tile's GFX
         BRA C3B98B      ; Skip a line
C3B988:  JSR C3BA77      ; Make blank tile
C3B98B:  PLA             ; Mold row flags
         PLY             ; Columns left
         DEY             ; One less left
         BNE C3B97D      ; Loop till last

; Fork: Handle next 8-tile row
C3B990:  REP #$20        ; 16-bit A
         INC $E0         ; Mold data adr +1
         SEP #$20        ; 8-bit A
         DEC $E6         ; One less row
         BNE C3B96E      ; Loop till last

; Fork: Set position and load colors
C3B99A:  JSR C3B9A0      ; Set tilemap ptr
         JMP C3BAC7      ; Load enemy pal

; Position Colosseum enemy based on size
C3B9A0:  STZ $E0         ; Blank rows: 0
         STZ $E4         ; Rel pos LB: 0
         STZ $E5         ; Rel pos HB: 0
         STZ $E3         ; Clear filled cols
         LDX $00         ; 1st: Bottom row
         LDA $99         ; Monster size
         CMP #$08        ; 8x8 tiles?
         BNE C3B9E6      ; Branch if not

; Fork: Count blank rows, identify filled columns (8x8)
C3B9B0:  LDA $7E9D89,X   ; Blank row here?
         BNE C3B9BD      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; Point 1 row up
         CMP #$08        ; Bogus...
         BNE C3B9B0      ; Test next row
C3B9BD:  LDX $00         ; 1st: Bottom row
C3B9BF:  LDA $7E9D89,X   ; Row's filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; Point 1 row up
         CPX #$0008      ; Done all 8 rows?
         BNE C3B9BF      ; Loop if not

; Fork: Position 8x8 enemy based on empty columns
C3B9CD:  ROR $E3         ; Empty column here?
         BCS C3B9D5      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3B9CD      ; Test next column
C3B9D5:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3A51      ; X+4, Y+8 tiles
         STA $E7         ; Save tilemap ptr
         BRA C3BA24      ; Adjust Y position

; Fork: Count blank rows, identify R-Half's filled columns (16x16)
C3B9E6:  LDA $7E9D89,X   ; Row's right half
         ORA $7E9D8A,X   ; L-Half empty too?
         BNE C3B9F9      ; Branch if not
         INC $E0         ; Blank rows +1
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B9E6      ; Loop if not
C3B9F9:  LDX $00         ; 1st: Bottom row
C3B9FB:  LDA $7E9D89,X   ; R-Half filled cols
         ORA $E3         ; Add prior rows'
         STA $E3         ; Save merged rows
         INX             ; 8-tile index +1
         INX             ; 8-tile index +1
         CPX #$0020      ; Done all 16 rows?
         BNE C3B9FB      ; Loop if not

; Fork: Position 16x16 enemy based on empty columns
C3BA0A:  ROR $E3         ; Empty column?
         BCS C3BA12      ; Branch if not
         INC $E4         ; Relative pos +1
         BRA C3BA0A      ; Test next column
C3BA12:  LSR $E4         ; If odd-numbered:
         ASL $E4         ; Relative pos -1
         REP #$21        ; 16-bit A; C-
         LDA $E4         ; Relative position
         ADC #$3849      ; Add base address
         STA $E7         ; Save tilemap ptr

; Fork: Adjust Y position based on enemy and blank rows
C3BA24:  SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $0206       ; Enemy number
         TAX             ; Index it
         LDA $ECE800,X   ; Modifier index
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JMP (C3BA36,X)  ; Shift enemy

; Jump table for the above
C3BA36:  dw C3BA40       ; Shift up by 3
         dw C3BA65       ; Shift down by $E0
         dw C3BA4F       ; Shift down by $E0 - 1
         dw C3BA57       ; Shift down by $E0 + 1
         dw C3BA5B       ; Shift down by $E0 - 3

; Shift enemy up by 3 tiles
C3BA40:  STZ $E0         ; Blank rows: 0
         REP #$20        ; 16-bit A
         LDA $E7         ; Tilemap ptr
         SEC             ; Prepare SBC
         SBC #$00C0      ; Go 3 rows up
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Shift enemy down by $E0 - 1
C3BA4F:  DEC $E0         ; Blank rows -1
         BPL C3BA55      ; Branch if 0+
         STZ $E0         ; Blank rows: 0
C3BA55:  BRA C3BA65      ; Shift enemy

; Shift enemy down by $E0 + 1
C3BA57:  INC $E0         ; Blank rows +1
         BRA C3BA65      ; Shift enemy

; Shift enemy down by $E0 - 3
C3BA5B:  DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         DEC $E0         ; Blank rows -1
         BPL C3BA65      ; Branch if 0+
         STZ $E0         ; Blank rows: 0

; Shift enemy down by $E0
C3BA65:  TDC             ; ...
         LDA $E0         ; Blank rows
         JSR x64         ; x64
         ADC $E7         ; Add map ptr
         STA $91         ; Save map ptr
         SEP #$20        ; 8-bit A
         RTS

; Create a blank tile at current location in VRAM
C3BA77:  REP #$20        ; 16-bit A
         LDA #$0010      ; Loop counter
C3BA80:  STZ $2118       ; 8 px, 2 planes
         DEC A           ; Counter -1
         BNE C3BA80      ; Loop till 0
         SEP #$20        ; 8-bit A
         RTS

; Upload current tile from monster's tileset
C3BA8B:  TXY             ; GFX index
         LDA $FF         ; Has 8 colors?
         BNE C3BA96      ; Branch if so
         LDX #$0010      ; Bytes: 32
         BRA C3BAB2      ; Load tile GFX

; Fork: Load 8-color tile, encode as 4bpp
C3BA96:  LDX #$0008      ; Bytes: 16
         JSR C3BAB2      ; Load rows' LSBs
         LDX #$0008      ; Rows left: 8
         TDC             ; Clear A
C3BAA3:  LDA [$F5],Y     ; GFX row's MSBs
         REP #$20        ; 16-bit A
         STA $2118       ; Save in VRAM
         SEP #$20        ; 8-bit A
         INY             ; GFX index +1
         DEX             ; One less row
         BNE C3BAA3      ; Loop till last
         TYX             ; GFX index
         RTS

; Fork: Upload specified number of words
C3BAB2:  REP #$20        ; 16-bit A
C3BAB7:  LDA [$F5],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; GFX index +1
         INY             ; GFX index +1
         DEX             ; Counter -1
         BNE C3BAB7      ; Loop till 0
         SEP #$20        ; 8-bit A
         TYX             ; GFX index
         RTS

; Load monster's palette
C3BAC7:  REP #$20        ; 16-bit A
         LDA $F1         ; Palette index
         AND #$03FF      ; Clear flags
         JSR x16         ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDY #$30A9      ; 7E/30A9
         STY $2181       ; Set WRAM LBs
         LDY #$0020      ; Colors: 16
C3BADE:  LDA $D27820,X   ; Color data
         STA $2180       ; To BG pal 3
         INX             ; ROM index +1
         DEY             ; One less byte
         BNE C3BADE      ; Loop till last
C3BAE9:  RTS

; Create Colosseum member 1
C3BAEA:  LDY $6D         ; Actor's address
         BEQ C3BAE9      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E4F      ; Text position
         JSR C3BB52      ; Draw name; OAM
         LDX #$A820      ; OBJ pos: 32, 168
         LDA $69         ; Actor's slot
         BRA C3BB60      ; Init sprite

; Create Colosseum member 2
C3BB04:  LDY $6F         ; Actor's address
         BEQ C3BAE9      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E5D      ; Text position
         JSR C3BB52      ; Draw name; OAM
         LDX #$A858      ; OBJ pos: 88, 168
         LDA $6A         ; Actor
         BRA C3BB60      ; Init sprite

; Create Colosseum member 3
C3BB1E:  LDY $71         ; Actor's address
         BEQ C3BAE9      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E6B      ; Text position
         JSR C3BB52      ; Draw name; OAM
         LDX #$A890      ; OBJ pos: 144, 168
         LDA $6B         ; Actor's slot
         BRA C3BB60      ; Init sprite

; Create Colosseum member 4
C3BB38:  LDY $73         ; Actor's address
         BEQ C3BAE9      ; Exit if nobody
         STY $67         ; Memorize it
         LDY #$7E79      ; Text position
         JSR C3BB52      ; Draw name; OAM
         LDX #$A8C8      ; OBJ pos: 200, 168
         LDA $6C         ; Actor's slot

; Create Colosseum actor sprite, excluding enemy Shadow
C3BB60:  PHX             ; Save position
         ASL A           ; Actor x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C370DB,X  ; Actor address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         TDC             ; Clear A
         LDA $14,X       ; Status
         AND #$20        ; Imp?
         BEQ C3BB77      ; Branch if not
         TDC             ; Clear A
         LDA #$0F        ; Use Imp set
         BRA C3BB7E      ; Skip a line
C3BB77:  LDA $01,X       ; Sprite set
C3BB7E:  JSR C3808E      ; Set anim ptr
         TYX             ; Queue index
         PLY             ; Position
         JSR objpos      ; Set sprite's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         RTS

; Draw Colosseum member's name, queue sprite function
C3BB52:  JSR C3356A      ; Draw actor name
         LDY #C381F3     ; C3/81F3
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue index
         TDC             ; Clear A
         RTS

; Load opponent and prize data for item bet
C3BB99:  TDC             ; Clear A
         LDA $0205       ; Item bet
         REP #$20        ; 16-bit A
         ASL A           ; x2
         ASL A           ; x4
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $D0F200,X   ; Opponent
         STA $0206       ; Save in RAM
         LDA $D0F202,X   ; Prize
         STA $0207       ; Save in RAM
         LDA $D0F203,X   ; Hide Prize flag
         STA $0209       ; Save in RAM
         RTS             ; ^ Read below

; Draw Colosseum bet
C3BBBA:  LDA $0205       ; Item bet
         LDY #$78EF      ; Text position
         BRA C3BBD0      ; Draw item name

; Draw Colosseum prize
C3BBC2:  LDA $0209       ; Hide prize?
         BNE C3BBF3      ; Use "???" if so
         LDA $0207       ; Prize
         LDY #$78D1      ; Tilemap ptr
C3BBD0:  PHA             ; Save item
         JSR C335E1      ; Set position
         PLA             ; Item
         JSR C3CFC3      ; Load name
         JMP C387B9      ; Draw name

; Fork: Draw question marks
C3BBF3:  LDY #C3BD8E     ; Text pointer
         JMP C302F9      ; Draw string

; Draw monster's name for Colosseum
C3BBFA:  LDY #$7C11      ; Tilemap ptr
         JSR C335E1      ; Set position
         JSR C35A64      ; Define source
         LDA $0206       ; Opponent
         JSR C38BF2      ; Load name
         JMP C387B_      ; Draw name

; Update Colosseum challenger's name and sprite
C3BC12:  TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         JSR C32DA6      ; Actor's address
         BEQ C3BC4C      ; Blank if nobody
         STY $67         ; Memorize it
         LDY #$7C35      ; Text position
         JSR C3356A      ; Draw actor name
         LDA #$02        ; Temp sprite: Y
         TSB $47         ; Set menu flag
         LDY #C382C9     ; C3/82C9
         JSR qanim2      ; Queue OAM fn
         LDA #$01        ; Anim mode: 1
         STA $7E3649,X   ; Set sprite's
         TXY             ; Queue index
         JSR C3BC59      ; Actor's slot
         LDX #$68B8      ; Pos: 184, 104
         JSR C3BB60      ; Init sprite
         BRA C3BC4F      ; Skip a line
C3BC4C:  JSR C3BC52      ; Blank name
C3BC4F:  SEC             ; Set to requeue
         RTS

; Blank challenger's name
C3BC52:  LDY #C3BD73     ; Text pointer
         JMP C30326      ; Draw 6 spaces

; Get party actor indicated by cursor
C3BC59:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $69,X       ; Actor slot
         RTS

; Update "VS" symbol from Colosseum
C3BC60:  BNE C3BC8B      ; If mode 1

; Mode 0: Initialize sprite
C3BC68:  INC $3649,X     ; Mode +1
         LDA #$D8        ; Anim ptr HB
         LDY #$ED11      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDY #$6070      ; Pos: 112, 96
         JSR objpos      ; Set sprite's
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3BC8B:  JMP oamsec      ; Set OAM; requeue

; Handle D-Pad for Colosseum matchup menu
C3BC96:  JSR C307B0      ; Handle D-Pad
C3BC99:  LDY #C3BCA4     ; C3/BCA4
         JMP C306C3      ; Relocate cursor

; Load arena graphics, tilemap, and colors
C3BCB8:  REP #$20        ; 16-bit A
         LDA $E7168C     ; E8/0C49
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E7168E     ; Src HB: E8
         JSR C3BD5F      ; Unpack GFX A
         LDY #$6800      ; $6800
         STY $2116       ; Set VRAM ptr
         LDX $00         ; 1st: 7E/B68D
         LDY #$1000      ; End: 7E/C68C
         JSR C3BD33      ; Upload GFX A

; Fork: Unpack and upload graphics for upper half
C3BCDB:  REP #$20        ; 16-bit A
         LDA $E71692     ; E8/1841
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA $E71694     ; Src HB: E8
         JSR C3BD5F      ; Unpack GFX B
         LDY #$7000      ; $7000
         STY $2116       ; Set VRAM ptr
         LDX $00         ; 1st: 7E/B68D
         LDY #$1000      ; End: 7E/C68C
         JSR C3BD33      ; Upload GFX B

; Fork: Unpack battle tilemap, convert to menu format
C3BCFE:  REP #$20        ; 16-bit A
         LDA $E7187A     ; E7/652B
         TAY             ; Set src LBs
         SEP #$20        ; 8-bit A
         LDA #$E7        ; Src HB: E7
         JSR C3BD5F      ; Unpack map
         JSR C3BD45      ; Convert map

; Fork: Load colors
C3BD12:  LDX #$005F      ; Colors: 48
C3BD27:  LDA $E70AB0,X   ; Color data
         STA $7E30C9,X   ; To BG pal 4/5/6
         DEX             ; Index -1
         BPL C3BD27      ; Loop till < 0
         RTS

; Upload current graphics set for arena background
C3BD33:  STY $E7         ; Set src end
         REP #$20        ; 16-bit A
C3BD35:  LDA $7EB68D,X   ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INX             ; Index +1
         INX             ; Index +1
         CPX $E7         ; Past range?
         BNE C3BD35      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Convert and relocate decompressed arena tilemap
C3BD45:  LDX $00         ; Index: 0
         REP #$20        ; 16-bit A
C3BD49:  LDA $7EB68D,X   ; Attributes
         SEC             ; Prepare SBC
         SBC #$0380      ; Tile num -896
         STA $7E5949,X   ; Put in BG2a
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0580      ; Done 704?
         BNE C3BD49      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Decompress data for arena background
C3BD5F:  STY $F3         ; Set src LBs
         STA $F5         ; Set src HB
         LDY #$B68D      ; 7E/B68D
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         JSL $C2FF6D     ; Unpack data
         RTS

; Set to condense BG3 text in SwdTech naming menu
C3BD99:  LDX #$000C      ; Base index
C3BD9B:  LDA.L C3BDF3,X  ; BG3 V-Pan data
         STA $7E9BC9,X   ; Save in RAM
         DEX             ; Index -1
         BPL C3BD9B      ; Loop till < 0
         LDY #$9BC9      ; Source LBs
         LDA #$7E        ; Source HB
         JSR bg3v        ; Queue BG3 V-Pan
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set DMA mode
         LDA #$11        ; $2111
         STA $4361       ; To BG3 H-Scroll
         LDY #C3BDE6     ; C3/BDE6
         STY $4362       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4364       ; Set src HB
         LDA #$40        ; Channel: 6
         TSB $43         ; Queue HDMA-6
         RTS

; 3F: Initialize SwdTech naming menu
C3BE00:  JSR C335F7      ; Reset/Stop stuff
         JSR C37076      ; Reset BGs' X/Y
         LDA #$41        ; 64x32 at $4000
         STA $2109       ; Set BG3 map loc
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         JSR C3C123      ; Draw menu; VWF GFX
         STZ $4A         ; Char tbl index: 0
         STZ $5D         ; List cursor col: 1
         STZ $5F         ; List cursor row: 1
         JSR C3C07F      ; Load navig data
         JSR C3C088      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         LDY #C3C357     ; C3/C357
         JSR qanim1      ; Queue large arrow
         JSR C3BD99      ; Set to shift text
         LDA #$40        ; C3/BE37
         STA $27         ; Queue: Choice 1
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 40: Handle SwdTech naming choice 1
C3BE37:  JSR C3C033      ; Set to upload name
         JSR C3C085      ; Handle D-Pad
         JSR C3BF53      ; Handle L and R
         LDA $08         ; Pushing A?
         BPL C3BE67      ; Branch if not
         JSR C3C2F9      ; Create small arrow
         LDA $4D         ; Cursor column
         STA $5E         ; Set return loc
         LDA $4B         ; Cursor slot
         STA $28         ; Set altered slot
         LDY #C3C0AE     ; C3/C0AE
         JSR C30681      ; Load navig data
         LDA $5D         ; Former list column
         STA $4D         ; Set cursor column
         LDA $5F         ; Former list row
         STA $4E         ; Set cursor row
         JSR C3C0A8      ; Relocate cursor
         INC $26         ; Next: Choice 2
         JMP C30F1D      ; Sound: Click

; Fork: Handle Start
C3BE67:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BEQ C3BEEE      ; Exit if not
C3BE6D:  JSR C30F1D      ; Sound: Click
;        STZ $0205       ; Never read...
         JMP fdexit      ; Queue menu exit

; 41: Handle SwdTech naming choice 2
C3BE7A:  JSR C3C033      ; Set to upload name
         LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3BE91      ; Branch if not
         LDA $4E         ; Cursor row
         CMP #$07        ; On bottom row?
         BNE C3BE91      ; Branch if not
         LDA #$4E        ; C3/BEEF
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer

; Fork: Handle upward scrolling
C3BE91:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3BEA3      ; Branch if not
         LDA $4E         ; On top row?
         BNE C3BEA3      ; Skip if not
         LDA #$4F        ; C3/BF17
         STA $26         ; Next: Scroll
         LDA #$11        ; Frames: 17
         STA $20         ; Set scroll timer

; Fork: Handle L and R, plus intrapage navigation
C3BEA3:  JSR C3BF53      ; Handle L and R
         JSR C3C0A5      ; Handle D-Pad

; Fork: Handle Start
C3BEA9:  LDA $09         ; No-autofire keys
         BIT #$10        ; Pushing Start?
         BNE C3BE6D      ; Return if so

; Fork: Handle A
C3BEB1:  LDA $08         ; Pushing A?
         BPL C3BECB      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JSR C3BF3F      ; Replace letter
         LDA $5E         ; Altered letter
         CMP #$05        ; Rightmost?
         BEQ C3BEC6      ; Wrap if so
         INC A           ; Point to next
         BRA C3BEC7      ; Skip a line
C3BEC6:  TDC             ; Point to char 1
C3BEC7:  STA $5E         ; Set return pos
         BRA C3BED4      ; Next: Choice 1

; Fork: Handle B
C3BECB:  LDA $09         ; Pushing B?
         BPL C3BEEE      ; Exit if not
         JSR C30F14      ; Sound: Cursor

; Fork: Return to top of menu
C3BED4:  LDA $4D         ; Cursor column
         STA $5D         ; Set for return
         LDA $4E         ; Cursor row
         STA $5F         ; Set for return
         JSR C3C07F      ; Load navig data
         LDA $5E         ; Former position
         STA $4D         ; Set cursor column
         JSR C3C088      ; Relocate cursor
         LDA #$01        ; Mini arrow: Off
         TRB $46         ; Set menu flag
         LDA #$40        ; C3/BE37
         STA $26         ; Next: Choice 1
C3BEEE:  RTS

; 4E: Scroll to SwdTech naming page 2 if valid starting point
C3BEEF:  LDA $20         ; Timer expired?
         BEQ C3BF0C      ; Finalize if so
         LDA $4A         ; Bottom of P2?
         BNE C3BF12      ; Cancel if so
         REP #$21        ; 16-bit A; C-
         LDA $7E9BCD     ; BG3 V-Shift
         ADC #$0008      ; Go 8 px down
         BRA C3BF1_      ; Set for charset

; Fork: Resume control
C3BF0C:  LDA #$38        ; Chars per page
         STA $4A         ; Set page mod
         STZ $4E         ; Cursor row: 1
C3BF12:  LDA #$41        ; C3/BE37
         STA $26         ; Next: Choice 1
         RTS

; 4F: Scroll to SwdTech naming page 1 if valid starting point
C3BF17:  LDA $20         ; Timer expired?
         BEQ C3BF34      ; Finalize if so
         LDA $4A         ; Top of page 1?
         BEQ C3BF3A      ; Cancel if so
         REP #$20        ; 16-bit A
         LDA $7E9BCD     ; BG3 V-Shift
         SEC             ; Prepare SBC
         SBC #$0008      ; Go 8 px up
C3BF1_:  STA $7E9BCD     ; For upper chars
         STA $7E9BD0     ; For lower chars
         SEP #$20        ; 8-bit A
         RTS

; Fork: Restore control
C3BF34:  STZ $4A         ; Char tbl index
         LDA #$07        ; Row: 8th
         STA $4E         ; Set cursor's
C3BF3A:  LDA #$41        ; C3/BE37
         STA $26         ; Next: Choice 1
         RTS

; Replace character in SwdTech name
C3BF3F:  JSR C3C06E      ; Name data index
         CLC             ; Prepare ADC
         ADC $28         ; Get altered slot
         TAX             ; Index it
         LDA $4B         ; Cursor slot
         ADC #$80        ; Add base char
         ADC $4A         ; +56 if page 2
         STA $1CF8,X     ; Replace char
C3BF52:  RTS

; Handle L and R in SwdTech naming menu
C3BF53:  LDA $08         ; No-autofire keys
         BIT #$30        ; Pushing L or R?
         BEQ C3BF52      ; Exit if not
         JSR C30F0E      ; Sound: Cursor
         LDA $4A         ; On page 2?
         BNE C3BF78      ; Branch if so

; Fork: Switch to page 2
C3BF64:  LDA #$38        ; Chars per page
         STA $4A         ; Set tbl index
         REP #$20        ; 16-bit A
         LDA #$0030      ; BG3 V-Shift: 48
         BRA C3BF1_      ; Set for charset

; Fork: Switch to page 1
C3BF78:  STZ $4A         ; Char tbl index
         REP #$20        ; 16-bit A
         LDA #$FFB0      ; BG3 V-Shift: -80
         BRA C3BF1_      ; Set for charset

; Build description tilemap for SwdTech naming menu
C3BF8A:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDY #$01B0      ; Ends at 24, 7
         STY $E7         ; Set row's limit
         LDY #$0186      ; Starts at 4, 7
         LDX #$3680      ; Tile 640, pal 5
         JSR C3B0C6      ; Build row 1
         LDY #$01F0      ; Ends at 24, 8
         STY $E7         ; Set row's limit
         LDY #$01C6      ; Starts at 4, 8
         LDX #$3681      ; Tile 641, pal 5
         JMP C3B0C6      ; Build row 2

; Load and upload VWF description graphics for renamed SwdTech
C3BFB3:  LDY #$0280      ; Bytes: 640
         JSR clr_vwf     ; Clear GFX buffer
         JSR C35D5D      ; Load description
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDX $00         ; Char index: 0
C3BFE2:  LDA $7E9EC9,X   ; Name character
         BEQ C3BFF3      ; If terminator
         JSR C3B1EC      ; Decode char
         JSR C3B227      ; Load graphics
         INX             ; Char index +1
         BRA C3BFE2      ; Do next char

; Fork: Upload description graphics
C3BFF3:  LDY #$7400      ; $7400
         STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0700      ; Bytes: 1792
         STY $19         ; Set data size
         JSR C31517      ; Upload graphics
         JMP C30FF4      ; Null VRAM ptr

; Build tilemap for name of renamed SwdTech
C3C00A:  LDX #$8049      ; Base: 7E/8049
         STX $EB         ; Set map ptr LBs
         LDY #$00B0      ; Ends at 24, 3
         STY $E7         ; Set row's limit
         LDY #$009E      ; Starts at 16, 3
         LDX #$3600      ; Tile 512, pal 5
         JSR C3B0C6      ; Build row 1
         LDY #$00F0      ; Ends at 24, 4
         STY $E7         ; Set row's limit
         LDY #$00DE      ; Starts at 16, 4
         LDX #$3601      ; Tile 513, pal 5
         JMP C3B0C6      ; Build row 2

; Load and set to upload VWF string graphics for renamed SwdTech
C3C033:  LDY #$0120      ; Bytes: 288
         JSR clr_vwf     ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA #$06        ; Letters: 6
         STA $F1         ; Set counter
         JSR C3C06E      ; Define X
C3C048:  LDA $1CF8,X     ; Name letter
         LDY #$3F40      ; Base: C4/D400
         STY $EB         ; Set font index
         JSR C3B227      ; Load graphics
         INX             ; Char index +1
         DEC $F1         ; One less char
         BNE C3C048      ; Loop till last
         LDY #$7000      ; $7000
         STY $1B         ; Set VRAM ptr
         LDY #$A271      ; 7E/A271
         STY $1D         ; Set src LBs
         LDY #$0120      ; Bytes: 288
         STY $19         ; Set data size
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         RTS

; Compute SwdTech name data index
C3C06E:  TDC             ; Clear A
         LDA $0201       ; SwdTech
         XBA             ; Put it in B
         LDA #$06        ; Name data size
         JSR mul8        ; Tech x size
         TAX             ; Index product
         RTS

; Load navigation data for name area in SwdTech naming menu
C3C07F:  LDY #C3C08E     ; C3/C08E
         JMP C30681      ; Load navig data

; Handle D-Pad for name area in SwdTech naming menu
C3C085:  JSR C307B0      ; Handle D-Pad
C3C088:  LDY #C3C093     ; C3/C093
         JMP C306C3      ; Relocate cursor

; Handle D-Pad for SwdTech naming menu options
C3C0A5:  JSR C307B0      ; Handle D-Pad
C3C0A8:  LDY #C3C0B3     ; C3/C0B3
         JMP C306C3      ; Relocate cursor

; Draw SwdTech naming menu, upload kanji graphics
C3C123:  LDX #C3C238     ; C3/C238
         JSR boxes_      ; Upload windows
         JSR bg1b_cl     ; Clear BG1 A+B
         JSR C3C1F2      ; Draw gauge
         JSR C3C1CA      ; Draw tech number
         JSR C30E93      ; Upload BG1 A+B

; Fork: Build tilemap for character set
C3C147:  JSR bg3b_cl     ; Clear BG3 A+B
         JSR C3D24D      ; Color: User's
         LDX #$7849      ; Base: 7E/7849
         STX $EB         ; Set map ptr LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set ptr HB
         LDX $00         ; ROM index: 0
C3C15C:  REP #$20        ; 16-bit A
         LDA.L C3C18A,X  ; Tilemap index
         TAY             ; Index it
         INX             ; ROM index +1
         INX             ; ROM index +1
         LDA.L C3C18A,X  ; Base attribs
         INX             ; ROM index +1
         INX             ; ROM index +1
         PHX             ; Memorize it
         TAX             ; X = Attribs
         JSR C3C25A      ; Draw 7 chars
         PLX             ; ROM index
         CPX #$0040      ; Done 8x2 rows?
         BNE C3C15C      ; Loop if not

; Fork: Upload graphics and tilemaps
C3C176:  SEP #$20        ; 8-bit A
         JSR C3C2A5      ; Load charset GFX
         JSR C3BF8A      ; Build desc map
         JSR C3BFB3      ; Upload desc GFX
         JSR C3C00A      ; Build name map
         JSR C3C033      ; Queue name GFX DMA
         JMP C30ED9      ; Upload BG3 A+B

; Base position and attributes for charset in SwdTech naming menu
C3C18A:  dw $0008,$3400  ; Page 1, row 1
         dw $0088,$341C  ; Page 1, row 2
         dw $0108,$3438  ; Page 1, row 3
         dw $0188,$3454  ; Page 1, row 4
         dw $0208,$3470  ; Page 1, row 5
         dw $0288,$348C  ; Page 1, row 6
         dw $0308,$34A8  ; Page 1, row 7
         dw $0388,$34C4  ; Page 1, row 8
         dw $0408,$34E0  ; Page 2, row 1
         dw $0488,$34FC  ; Page 2, row 2
         dw $0508,$3518  ; Page 2, row 3
         dw $0588,$3534  ; Page 2, row 4
         dw $0608,$3550  ; Page 2, row 5
         dw $0688,$356C  ; Page 2, row 6
         dw $0708,$3588  ; Page 2, row 7
         dw $0788,$35A4  ; Page 2, row 8

; Draw "SwdTech <#>" in SwdTech naming menu
C3C1CA:  JSR C3D24D      ; Color: User's
         LDY #C3C251     ; Text pointer
         JSR C30326      ; Draw "SwdTech"
         LDA $0201       ; SwdTech number
         LDX #$38DD      ; Tilemap ptr
         JMP C341F7      ; Draw value

; Draw gauge in SwdTech naming menu
C3C1F2:  JSR txt30       ; Color: Gray
         LDY #C3C244     ; Text pointer
         JSR C302F9      ; Draw gauge
         TDC             ; Clear A
         LDA $0201       ; SwdTech
         BEQ C3C27B      ; If Dispatch
         TAX             ; Set counter
         LDY #$3911      ; Tilemap ptr
         JSR C335E1      ; Set position
C3C216:  LDA.B #!bar8    ; Filler tile
         STA $2180       ; Add to string
         DEX             ; One less left
         BNE C3C216      ; Loop till last
         STZ $2180       ; End string
         JMP C38FD1      ; Draw filling

; Build tilemap for current row of kanji in SwdTech naming menu
C3C25A:  SEP #$20        ; 8-bit A
         LDA #$07        ; Characters: 7
         STA $E2         ; Set counter
C3C260:  REP #$20        ; 16-bit A
         PHY             ; Save map index
         PHX             ; Save attributes
         JSR C3C27C      ; Draw character
         PLX             ; Tile attributes
         TXA             ; Put them in A
         CLC             ; Prepare ADC
         ADC #$0004      ; Base tile num +4
         TAX             ; Put this in X
         PLY             ; Tilemap index
         TYA             ; Put it in A
         CLC             ; Prepare ADC
         ADC #$0008      ; Go 4 tiles right
         TAY             ; Reindex it
         SEP #$20        ; 8-bit A
         DEC $E2         ; One less char
         BNE C3C260      ; Loop till last
C3C27B:  RTS

; Build tilemap for current kanji from charset in SwdTech naming menu
C3C27C:  STX $E0         ; Save attributes
         LDA $E0         ; Put them in A
         STA [$EB],Y     ; Set NW tile's
         INC $E0         ; Tile number +1
         INC $E0         ; Tile number +1
         INY             ; Map index +1
         INY             ; Map index +1
         LDA $E0         ; Tile attributes
         STA [$EB],Y     ; Set NE tile's
         DEC $E0         ; Tile number -1
         DEY             ; Map index -1
         DEY             ; Map index -1
         TYA             ; Put it in A
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         TAY             ; Reindex it
         LDA $E0         ; Tile attributes
         STA [$EB],Y     ; Set SW tile's
         INY             ; Map index +1
         INY             ; Map index +1
         INC $E0         ; Tile number +1
         INC $E0         ; Tile number +1
         LDA $E0         ; Tile attributes
         STA [$EB],Y     ; Set SE tile's
         RTS

; Load VWF graphics for charset in SwdTech naming menu
C3C2A5:  STZ $E4         ; Char slot: 1st
         LDY #$6000      ; $6000
         STY $F1         ; Set VRAM ptr
C3C2AC:  JSR C3C2DE      ; Load char GFX
         LDY $F1         ; VRAM pointer
         JSR C3AF53      ; Upload graphics
         REP #$21        ; 16-bit A; C-
         LDA $F1         ; VRAM pointer
         ADC #$0020      ; Skip 4 tiles
         STA $F1         ; Save changes
         SEP #$20        ; 8-bit A
         INC $E4         ; Char slot +1
         LDA $E4         ; Char slot
         CMP #$70        ; Done all 112?
         BNE C3C2AC      ; Loop if not
         JMP C30FF4      ; Null VRAM ptr

; Load VWF graphics for charset slot in SwdTech naming menu
C3C2DE:  LDY #$0040      ; Bytes: 64
         JSR clr_vwf     ; Clear GFX buffer
         STZ $8D         ; String width: 0
         STZ $ED         ; VRAM index LB: 0
         STZ $EE         ; VRAM index HB: 0
         LDA $E4         ; Slot number
         CLC             ; Prepare ADC
         ADC #$80        ; Now tile number
         LDY #$3F40      ; Base: C4/D400
         STY $EB         ; Set font index
         JMP C3B227      ; Load graphics

; Create small arrow in SwdTech naming menu
C3C2F9:  LDY #C3C312     ; C3/C312
         JSR qanim2      ; Queue OAM fn
         JMP C3A5D_      ; Set position

; Update small arrow in SwdTech naming menu
C3C312:  BNE C3C335      ; If mode 1

; Mode 0: Initialize arrow
C3C31A:  LDA #$01        ; Show arrow: Y
         TSB $46         ; Set menu flag
         LDY #C3C34E     ; Anim table ptr
         JSR anm_c3      ; Set arrow's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C3C335:  LDA $46         ; Menu flags
         LSR A           ; Delete arrow?
         BCC C3C342      ; Dequeue if so
         JMP oamsec      ; Set OAM; requeue
C3C342:  CLC             ; Set to dequeue
         RTS

; Update large arrow in SwdTech naming menu
C3C357:  BNE C3C382      ; If mode 1

; Mode 0: Initialize arrow
C3C35F:  LDY #C3C3A3     ; Anim table ptr
         JSR anm_c3      ; Set arrow's
         LDY #$4878      ; Pos: 120, 72
         JSR objpos      ; Set arrow's
         JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain arrow
C3C382:  TXY             ; Queue index
         LDX $00         ; Arrow: Down
         LDA $4A         ; On first page?
         BEQ C3C38C      ; Branch if so
         INX #2          ; Arrow: Up
C3C38C:  REP #$20        ; 16-bit A
         LDA.L C3C39F,X  ; Anim table ptr
         STA $32C9,Y     ; Set arrow's
         JMP oamsec      ; Set OAM; requeue

; 24: Initialize shop menu
C3C3C0:  JSR C335F7      ; Reset/Stop stuff
         JSR C37076      ; Reset BGs' X/Y
;        LDA #$03        ; 64x64 at $0000
;        STA $2107       ; Set BG1 map loc
         LDA #$02        ; Main cursor: On
         STA $46         ; Bar/Blinker: Off
         STZ $4A         ; Sell list scroll: 0
         JSR C3C7DD      ; Load navig data
         JSR C3C7E6      ; Relocate cursor
         JSR C30833      ; Queue cursor OAM
         JSR C3C81B      ; Draw menu; desc
         JSR C385DA      ; Set to shift text
         LDY #C3CF92     ; C3/CF92
         STY $4352       ; Redirect BG3's
         LDA #$25        ; C3/C3F2
         STA $27         ; Queue: Sustain menu
         LDA #$01        ; C3/1DE4
         STA $26         ; Next: Fade-in
         JMP C33609      ; BRT:1 + NMI

; 25: Sustain main shop menu
C3C3F2:  JSR C3C7E3      ; Handle D-Pad
         LDA $08         ; Pushing A?
         BPL C3C401      ; Branch if not
         JSR C30F1D      ; Sound: Click
         JMP C3C6E9      ; Handle choice

; Fork: Handle B
C3C401:  LDA $09         ; Pushing B?
         BPL C3C48F      ; Exit if not
         JSR C30F14      ; Sound: Cursor
C3C40A: ;STZ $0205       ; Never read...
         JMP fdexit      ; Queue menu exit

; 26: Handle buy item list
C3C414:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         JSR C30FA4      ; Queue text upload
         JSR C3C7FD      ; Handle D-Pad
         JSR C3CBDF      ; Draw qty owned
         JSR C3CC03      ; Draw qty worn

; Fork: Handle B
C3C424:  LDA $09         ; Pushing B?
         BPL C3C430      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         JMP C3C6B7      ; Exit submenu

; Fork: Handle A
C3C430:  LDA $08         ; Pushing A?
         BPL C3C48F      ; Exit if not
         JSR C3C786      ; Set buy limit
         JMP C3C73D      ; Test GP, stock

; Set description to be displayed and to ignore joypad
C3C43D:  LDA #$20        ; D-Pad: Ignore
         TSB $45         ; Set desc flag
desc_on: LDA #$10        ; Description: On
         TRB $45         ; Set menu flag
         RTS

; Load item description for Buy menu
C3C446:  JSR C38A89      ; Set desc ptrs
         JMP C35D8D      ; Load description

; Load item description for Sell menu
C3C44F:  JSR C38A89      ; Set desc ptrs
         JSR C3CF26      ; Selected item
         JMP C35D95      ; Load description

; 27: Handle buy order menu
C3C45C:  JSR C3C43D      ; Set desc flags
         JSR C3C446      ; Load description
         JSR C3CAAA      ; Get order value
         JSR C3CB05      ; Draw size, value

; Fork: Buy quantity +1
C3C468:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3C490      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Buy quantity
         CMP $6A         ; At capacity?
         BEQ C3C4F5      ; Abort if so
         INC $28         ; Quantity +1
         JSR C3CAAA      ; Get new cost
         REP #$20        ; 16-bit A
         LDA $1860       ; Gold LBs
         CMP $F1         ; C- if < cost's
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3C48F      ; Exit if not
         DEC $28         ; Quantity -1
C3C48F:  RTS

; Fork: Buy quantity -1
C3C490:  LSR A           ; Pushing left?
         BCC C3C4A1      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Buy quantity
         DEC A           ; One?
         BEQ C3C4F5      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Buy quantity +10
C3C4A1:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3C4DA      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $6A         ; At capacity?
         BEQ C3C4B5      ; Retain if so
         BCS C3C4D6      ; Abort if over
C3C4B5:  STA $28         ; Set order size
         JSR C3CAAA      ; Get new cost
         REP #$20        ; 16-bit A
         LDA $1860       ; Gold LBs
         CMP $F1         ; C- if < cost's
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         SBC $F3         ; So, GP < cost?
         BCS C3C4D2      ; Exit if not
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         STA $28         ; Save changes
C3C4D2:  RTS

; Fork: Leave quantity unchanged...
C3C4D6:  LDA $28         ; Buy quantity
         BRA C3C4B5      ; Test cost

; Fork: Buy quantity -10
C3C4DA:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3C4F5      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Buy quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3C4F1      ; Use 1 if < 0
         BEQ C3C4F5      ; Abort if 0
         STA $28         ; Save changes
         RTS

; Fork: Set buy quantity to 1
C3C4F1:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3C4F5:  LDA $09         ; Pushing B?
         BPL C3C501      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         JMP C3C70A      ; Exit submenu

; Fork: Handle A
C3C501:  LDA $08         ; Pushing A?
         BPL C3C4D2      ; Exit if not
         JSR C30F39      ; Sound: Cash
         JSR C3CF1D      ; Bought item
         LDY $00         ; Item slot: 1
C3C513:  CMP $1869,Y     ; Slot holds it?
         BEQ C3C538      ; Qty +1 if so
         INY             ; Item slot +1
         CPY #$0100      ; Done all 256?
         BNE C3C513      ; Loop if not
         LDY $00         ; Item slot: 1
C3C520:  LDA $1869,Y     ; Item in slot
         INC A           ; None?
         BEQ C3C52A      ; Overwrite if so
         INY             ; Item slot +1
         BRA C3C520      ; Try next slot

; Fork: Put bought item in empty slot
C3C52A:  LDA $28         ; Quantity bought
         STA $1969,Y     ; Assign to slot
         LDA $7E9D89,X   ; Bought item
         STA $1869,Y     ; Assign to slot
         BRA C3C541      ; Reduce GP, etc.

; Fork: Add quantity bought to stock
C3C538:  LDA $28         ; Quantity bought
         CLC             ; Prepare ADC
         ADC $1969,Y     ; Add qty owned
         STA $1969,Y     ; Set qty owned

; Fork: Reduce party's GP, leave submenu
C3C541:  JSR C3CAAA      ; Get order value
         SEC             ; Prepare SBC
         LDA $1860       ; Gold LB
         SBC $F1         ; Deduct cost's
         STA $1860       ; Save changes
         REP #$20        ; 16-bit A
         LDA $1861       ; Gold HBs
         SBC $F2         ; Deduct cost's
         STA $1861       ; Save changes
         SEP #$20        ; 8-bit A
         JSR C33369      ; Cap GP
         LDY #C3D327     ; Text pointer
         JSR C30326      ; Draw "Bye!"
         JMP C3C7D4      ; Set to exit

; 28: Return to Buy menu after delay
C3C565:  LDA $20         ; Delay expired?
         BNE C3C56C      ; Exit if not
         JMP C3C70A      ; Leave submenu
C3C56C:  RTS

; 29: Handle sell item list
C3C56D:  LDA #$10        ; Reset/Stop desc
         TSB $45         ; Set menu flag
         TDC             ; Clear A
         STA $2A         ; List type: Stock
         JSR C30F68      ; Queue list upload
         JSR C31FCA      ; Handle L and R
         BCS C3C56C      ; Exit if pushed
         JSR C384A9      ; Handle D-Pad

; Fork: Handle B
C3C57F:  LDA $09         ; Pushing B?
         BPL C3C58B      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         JMP C3C6B7      ; Exit submenu

; Fork: Handle A
C3C58B:  LDA $08         ; Pushing A?
         BPL C3C56C      ; Exit if not
         JSR C3CF26      ; Selected item
         INC A           ; Empty slot?
         BEQ C3C5C6      ; Fail if so
         JSR C30F1D      ; Sound: Click
         LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         JSR C371A9      ; Blank item list
         JSR C30F68      ; Set to upload it
         JSR C313D3      ; Upload it now
         LDA #$2A        ; C3/C5CD
         STA $26         ; Next: Order menu
         LDX #$3408      ; Pos: 8, 52
         STX $55         ; Set cursor's
         JSR C3CA02      ; Draw blue text
         JSR C3CA30      ; Draw item info
         LDY #C3D316     ; Text pointer
         JSR C30326      ; Draw "How many?"
         JMP C3C7C4      ; Switch screen

; Play buzzer, pixelate screen
C3C5C6:  JSR C30F2B      ; Play buzzer
         JMP C330F8      ; Pixelate screen

; 2A: Handle sell order menu
C3C5CD:  JSR C3C43D      ; Set desc flags
         JSR C3C44F      ; Load description
         JSR C3CABC      ; Get order value
         JSR C3CB0E      ; Draw qty, offer

; Fork: Sell quantity +1
C3C5D9:  LDA $0B         ; Semi-auto keys
         LSR A           ; Pushing right?
         BCC C3C5EC      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Sell quantity
         CMP $64         ; Can sell more?
         BEQ C3C637      ; Abort if not
         INC $28         ; Quantity +1
         BRA C3C637      ; Handle B

; Fork: Sell quantity -1
C3C5EC:  LSR A           ; Pushing left?
         BCC C3C5FD      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Sell quantity
         DEC A           ; One?
         BEQ C3C637      ; Abort if so
         DEC $28         ; Quantity -1

; Fork: Sell quantity +10
C3C5FD:  LDA $0B         ; Semi-auto keys
         BIT #$08        ; Pushing up?
         BEQ C3C61B      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA #$0A        ; Quantity: 10
         CLC             ; Prepare ADC
         ADC $28         ; Add order size
         CMP $64         ; Owning enough?
         BCS C3C615      ; Limit if not
         STA $28         ; Set order size
         BRA C3C637      ; Handle B

; Fork: Limit sell quantity
C3C615:  LDA $64         ; Quantity owned
         STA $28         ; Set order size
         BRA C3C637      ; Handle B

; Fork: Sell quantity -10
C3C61B:  LDA $0B         ; Semi-auto keys
         BIT #$04        ; Pushing down?
         BEQ C3C637      ; Branch if not
         JSR C30F0E      ; Sound: Cursor
         LDA $28         ; Sell quantity
         SEC             ; Prepare SBC
         SBC #$0A        ; Subtract 10
         BMI C3C633      ; Use 1 if < 0
         BEQ C3C637      ; Abort if 0
         STA $28         ; Save changes
         BRA C3C637      ; Handle B

; Fork: Set sell quantity to 1
C3C633:  LDA #$01        ; Quantity: 1
         STA $28         ; Set order size

; Fork: Handle B
C3C637:  LDA $09         ; Pushing B?
         BPL C3C652      ; Branch if not
         JSR C30F14      ; Sound: Cursor
         LDX $00         ; Clear X
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         JSR C3C8B7      ; Clean up BG3
         LDY #C3D27E     ; Text pointer
         JSR C30326      ; Draw options
         JMP C3C726      ; Exit submenu

; Fork: Handle A
C3C652:  LDA $08         ; Pushing A?
         BPL .exit       ; Exit if not
         JSR C30F39      ; Sound: Cash
         JSR C3CABC      ; Get order value
         REP #$21        ; 16-bit A; C-
         LDA $1860       ; Gold LBs
         ADC $F1         ; Add cost's
         STA $1860       ; Save changes
         SEP #$20        ; 8-bit A
         LDA $1862       ; Gold HB
         ADC $F3         ; Add cost's + C
         STA $1862       ; Save changes
         LDA $64         ; Quantity owned
         CMP $28         ; Sold all of it?
         BEQ C3C68B      ; Branch if so
         JSR C3CF26      ; Define Y
         LDA $1969,Y     ; Quantity owned
         SEC             ; Prepare SBC
         SBC $28         ; Deduct qty sold
         STA $1969,Y     ; Save changes
         BRA C3C697      ; Skip 6 lines
.exit    RTS

; Fork: Clear item slot, leave submenu
C3C68B:  JSR C3CF26      ; Define Y
         LDA #$FF        ; Empty item
         STA $1869,Y     ; Put in slot
         TDC             ; Quantity: 0
         STA $1969,Y     ; Assign to slot
C3C697:  JSR C33369      ; Cap GP
         LDA #$2B        ; C3/C6A9
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         LDY #C3D327     ; Text pointer
         JMP C30326      ; Draw "Bye!"

; 2B: Return to Sell menu after delay
C3C6A9:  LDX $20         ; Delay expired?
         BNE C3C6E8      ; Exit if not
         STX $39         ; BG2 X-Pos: 0
         STX $3B         ; BG2 Y-Pos: 0
         BRA C3C726      ; Exit submenu

; Return to main shop menu
C3C6B7:  LDA #$C0        ; Scrollbar: Off
         TRB $46         ; Set anim index
         STZ $47         ; Actors: Off
         JSR C3C7DD      ; Load navig data
         JSR C3C7E6      ; Relocate cursor
         JSR C30F68      ; Set to upload BG1
         JSR C3C8AB      ; Clear BG1 maps
         JSR C313D3      ; Refresh screen
         JSR C30FA4      ; Queue BG3 upload
         JSR C3C8B7      ; Clean up BG3
         LDY #C3D27E     ; Text pointer
         JSR C30326      ; Draw options
         LDY #C3D2C2     ; Text pointer
         JSR C30326      ; Draw greeting
         LDY $00         ; Clear Y
         STY $39         ; Reset BG2 X-Pos
         STY $3B         ; Reset BG2 Y-Pos
         LDA #$25        ; C3/C3F2
         STA $26         ; Next: Shop menu
C3C6E8:  RTS

; Handle selected option in shop menu
C3C6E9:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         ASL A           ; Double it
         TAX             ; Index it
         JMP (C3C6F1,X)  ; Handle option

; Jump table
C3C6F1:  dw C3C6FA       ; BUY
         dw C3C71E       ; SELL
         dw C3C6F7       ; EXIT

; Exit shop
C3C6F7:  JMP C3C40A      ; Queue menu exit

; Initialize Buy menu
C3C6FA:  LDY #C3C806     ; C3/C806
         JSR C30681      ; Load navig data
         JSR C3C800      ; Relocate cursor
         LDA #$08        ; Arm waving: On
         TRB $47         ; Never off...
         JSR C3CFF5      ; Create actors
         JSR C3D196      ; Create signs
C3C70A:  LDY #$0100      ; X: 256
         STY $39         ; Set BG2 X-Pos
         LDY $00         ; Y: 0
         STY $3B         ; Set BG2 Y-Pos
         LDA #$26        ; C3/C414
         STA $26         ; Next: Buy list
         JSR C3C8E3      ; Draw all text
         JMP C3CC58      ; Build sign list

; Initialize Sell menu
C3C71E:  JSR C30FA4      ; Queue BG3 upload
         JSR C3CB37      ; Cursor/list/bar
         BRA C3C729      ; Skip a line

; Return to Sell menu
C3C726:  JSR C3CB59      ; Draw list; bar
C3C729:  JSR C3C8B7      ; Draw title, GP
         LDY #C3D27E     ; Text pointer
         JSR C30326      ; Draw options
         LDY #C3D300     ; Text pointer
         JSR C30326      ; Draw question
         LDA #$29        ; C3/C56D
         STA $26         ; Next: Sell list
         RTS

; Invoke buy order menu if justified
C3C73D:  JSR C3CF1D      ; Selected item
         JSR itm_cl1     ; Tool class?
         BNE C3C761      ; Branch if not
         JSR C3CBED      ; Define $64
         LDA $64         ; Owning none?
         BEQ C3C761      ; Test GP if so
         JSR C30F2B      ; Play buzzer
         LDY #C3D363     ; Text pointer
         JSR C30326      ; Draw excuse
         BRA C3C7D4      ; Set to exit

; Fork: Check if enough money
C3C761:  LDA $1862       ; GP > 65535?
         BNE C3C795      ; Ample if so
         TDC             ; ...
         LDA $4B         ; Selected slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Item's price
         CMP $1860       ; Got as much?
         SEP #$20        ; 8-bit A
         BEQ C3C795      ; Ample if so
         BCC C3C795      ; Or if more
         JSR C30F2B      ; Play buzzer
         LDY #C3D33D     ; Text pointer
         JSR C30326      ; Draw excuse
         BRA C3C7D4      ; Set to exit

; Sub: Define buy quantity limit
C3C786:  LDA $64         ; Qty in stock
         CLC             ; Prepare ADC
         ADC $65         ; Add qty worn
         STA $69         ; Set total owned
         LDA #$63        ; Quantity: 99
         SEC             ; Prepare SBC
         SBC $69         ; Sub total owned
         STA $6A         ; Set buy limit
         RTS

; Fork: Check if owning 99
C3C795:  LDA $69         ; Qty owned/worn
         CMP #$63        ; Under 99?
         BCC C3C7A7      ; Okay if so
         JSR C30F2B      ; Play buzzer
         LDY #C3D351     ; Text pointer
         JSR C30326      ; Draw "Too many!"
         BRA C3C7D4      ; Set to exit

; Fork: Can buy item
C3C7A7:  JSR C30F1D      ; Sound: Click
         LDX #$3408      ; Pos: 8, 52
         STX $55         ; Set cursor's
         LDA #$27        ; C3/C45C
         STA $26         ; Next: Order menu
         JSR C3CA02      ; Draw blue text
         JSR C3CA17      ; Draw item info
         LDY #C3D2EE     ; Text pointer
         JSR C30326      ; Draw "How many?"

; Fork: Switch screen
C3C7C4:  LDY #$0100      ; Y: 256
         STY $3B         ; Set BG2 Y-Pos
         LDY $00         ; X: 0
         STY $39         ; Set BG2 X-Pos
         JSR C3B0D9      ; Clear desc GFX
         JMP C3B037      ; Build desc map

; Set to return to Buy menu after delay
C3C7D4:  LDA #$28        ; C3/C565
         STA $26         ; Next: Exit
         LDA #$20        ; Frames: 32
         STA $20         ; Set delay
         RTS

; Load navigation data for main shop menu
C3C7DD:  LDY #C3C7EC     ; C3/C7EC
         JMP C30681      ; Load navig data

; Handle D-Pad for main shop menu
C3C7E3:  JSR C307B0      ; Handle D-Pad
C3C7E6:  LDY #C3C7F1     ; C3/C7F1
         JMP C306C3      ; Relocate cursor

; Handle D-Pad for Buy menu
C3C7FD:  JSR C307B0      ; Handle D-Pad
C3C800:  LDY #C3C80B     ; C3/C80B
         JMP C306C3      ; Relocate cursor

; Draw main shop menu and submenu windows, set to update description
C3C81B:  JSR bg2c_cl     ; Clear BG2 maps
         LDX #C3CB72     ; C3/CB72
         JSR boxes_      ; Draw windows
         JSR C30ECB      ; Upload BG2 C+D
         JSR C3C8AB      ; Clear BG1 maps
         JSR C3C8B7      ; Draw title, GP
         LDY #C3D27E     ; Text pointer
         JSR C30326      ; Draw options
         LDY #C3D2C2     ; Text pointer
         JSR C30326      ; Draw greeting
         JSR C31BFF      ; Queue desc anim
         JMP up_txt      ; Upload text maps

; Clear BG1 tilemaps
C3C8AB:  JSR C371B7      ; Clear BG1 map D
bg1c_cl: JSR C371B2      ; Clear BG1 map C
bg1b_cl: JSR C371AD      ; Clear BG1 map B
         JMP C371A9      ; Clear BG1 map A

; Draw shop title and party's gold, clear rest of BG3
C3C8B7:  JSR bg3c_cl     ; Clear BG3 A-C
         JSR C3CF2E      ; Draw title
;        JSR C3D252      ; Color: Blue
         LDY #C3D28B     ; Text pointer
         JSR C30326      ; Draw "GP"
         JSR C3D24D      ; Color: User's
         PEA $7A33       ; Text position
         JMP gp_pty      ; Draw GP total

; Draw all text for Buy menu
C3C8E3:  JSR C3C8B7      ; Draw title, GP
         LDY #C3D2D8     ; Text pointer
         JSR C30326      ; Draw "Help..."
         JSR C3D23C      ; Draw Owned, Eqpd
         LDY $00         ; Clear Y
         STY $F1         ; Menu slot: 1
         STZ $E6         ; List size: 0
C3C8F5:  REP #$20        ; 16-bit A
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C3C959,X  ; Tilemap ptr
         STA $7E9E89     ; Set position
         LDA $F1         ; Menu slot
;        CLC             ; Prepare ADC
         ADC $67         ; Add shop index
         INC A           ; Skip flags
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop item
         LDX $F1         ; Menu slot
         STA $7E9D89,X   ; Assign item
         CMP #$FF        ; Nothing?
         BEQ C3C941      ; Branch if so
         PHA             ; Memorize item
         JSR C3CFC3      ; Load name
         JSR C387B9      ; Draw name
         PLA             ; Item in slot
         JSR C38AA2      ; Compute index
         JSR C3C969      ; Define price
         JSR C305B1      ; Turn into text
         REP #$21        ; 16-bit A; C-
         LDA $7E9E89     ; Tilemap ptr
         ADC #$0056      ; Row +1, col +11
         TAX             ; Put sum in X
         JSR C3051D      ; Draw price
         INC $E6         ; List size +1
C3C941:  LDY $F1         ; Menu slot
         INY             ; Menu slot +1
         STY $F1         ; Save changes
         CPY #$0008      ; Done 8 items?
         BNE C3C8F5      ; Loop if not
         LDA $E6         ; List size
         STA $54         ; Set cursor limit
         JSR C3CBB2      ; Get qties owned
         JSR C3CBDF      ; Draw qty owned
         JMP C3CC03      ; Draw qty worn

; Define cost to buy item
C3C969:  REP #$20        ; 16-bit A
         LDA $D8501C,X   ; Base price
         JSR C3C989      ; Apply multiplier
         STA $F3         ; Memorize result
         LDA $F1         ; Menu slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $F3         ; Modified price
         STA $7E9F09,X   ; Set item price
         SEP #$20        ; 8-bit A
         RTS

; Apply price multiplier for Buy menu
C3C989:  PHA             ; Save price
         LDX $67         ; Shop index
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $C47AC0,X   ; Shop flags
         AND #$38        ; Get modifier
         REP #$20        ; 16-bit A
         LSR A           ; Put in b2-b4
         LSR A           ; Put in b1-b3
         TAX             ; Index it
         PLA             ; Base price
         JMP (C3C99E,X)  ; Apply modifier

; Jump table for price multipliers
C3C99E:  dw C3C9B2       ; 100%
         dw C3C9AC       ; 150%
         dw C3C9B3       ; 200%
         dw C3C9B5       ; 50%
         dw C3C9B7       ; 50% if female leads, 150% otherwise
         dw C3C9D3       ; 50% if male leads, 150% otherwise
         dw C3C9EF       ; 50% if Edgar leads

; Double price (unused)
C3C9B3:  ASL A           ; Double price
         RTS

; Halve price if female leads, raise by 50% otherwise (unused)
C3C9B7:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         BEQ C3C9CE      ; -50% if Terra
         CMP #$06        ; Celes?
         BEQ C3C9CE      ; Halve if so
         CMP #$08        ; Relm?
         REP #$20        ; 16-bit A
         BEQ C3C9CE      ; Halve if so
         PLA             ; Base price
         BRA C3C9AC      ; Add 50%
C3C9CE:  PLA             ; Base price

; Halve price
C3C9B5:  LSR A           ; Halve price
         RTS

; Halve price if male leads, raise by 50% otherwise (unused)
C3C9D3:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         BEQ C3C9EA      ; +50% if Terra
         CMP #$06        ; Celes?
         BEQ C3C9EA      ; +50% if so
         CMP #$08        ; Relm?
         REP #$20        ; 16-bit A
         BEQ C3C9EA      ; +50% if so
         PLA             ; Base price
         BRA C3C9B5      ; Halve it
C3C9EA:  PLA             ; Base price

; Increase price by 50% (unused)
C3C9AC:  STA $E7         ; Save price
         LSR A           ; Halve it
         CLC             ; Prepare ADC
         ADC $E7         ; Add base price
C3C9B2:  RTS

; Halve price if Edgar leads
C3C9EF:  PHA             ; Save price
         SEP #$20        ; 8-bit A
         LDA $0202       ; Leader sprite
         CMP #$04        ; Edgar?
         REP #$20        ; 16-bit A
         BEQ C3C9FD      ; Halve if so
         PLA             ; Base price
         RTS             ; Exit
C3C9FD:  PLA             ; Base price
         BRA C3C9B5      ; Halve it

; Draw blue text for shop order menu, position item name
C3CA02:  JSR C30FA4      ; Queue BG3 upload
         JSR C3C8B7      ; Clean up BG3
         JSR C3D23C      ; Draw Owned, Eqpd
         LDY #$79CF      ; Tilemap ptr
         JMP C335E1      ; Set item position

; Draw item specs for buy order menu, reset buy quantity
C3CA17:  JSR C3CA49      ; Draw power info
         JSR C3CBDF      ; Draw qty owned
         JSR C3CC03      ; Draw qty worn
         JSR C3CF1D      ; Selected item
         JSR C3CFC3      ; Load name
         JSR C387B9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3CB05      ; Draw size, value

; Draw item specs for sell order menu, reset sell quantity
C3CA30:  JSR C3CBF8      ; Draw qty owned
         JSR C3CEC1      ; Draw qty worn
         JSR C3CA4F      ; Draw power info
         JSR C3CF26      ; Selected item
         JSR C3CFC3      ; Load name
         JSR C387B9      ; Draw name
         LDA #$01        ; Quantity: 1
         STA $28         ; Set order size
         JMP C3CB0E      ; Draw size, value

; Draw power-related text for Buy menu
C3CA49:  JSR C3CF1D      ; Selected item
         BRA C3CA55      ; Draw power info

; Draw power-related text for Sell menu
C3CA4F:  JSR C3CF26      ; Selected item

; Draw power-related text for Buy or Sell menu
C3CA55:  JSR itm_cl1     ; Tool class?
         BEQ C3CB04      ; Exit if so
         CMP #$06        ; Consumable?
         BEQ C3CB04      ; Exit if so
         DEC A           ; Weapon?
         BEQ C3CA8D      ; Branch if so
         JSR C3D24D      ; Color: User's
         LDA $D85014,X   ; Defense
         JSR C30563      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C30543      ; Draw 3 digits
         JSR C3D252      ; Color: Blue
         LDY #C3D2B7     ; Text pointer
         JSR C30326      ; Draw "Defense"
         LDY #C3D2BE     ; Text pointer
         JSR C302F9      ; Draw ".."
         JMP C3D24D      ; Color: User's

; Fork: Handle weapon
C3CA8D:  JSR C3D24D      ; Color: User's
         LDA $D85014,X   ; Bat.Pwr
         JSR C30563      ; Turn into text
         LDX #$7BA9      ; Text position
         JSR C30543      ; Draw 3 digits
         JSR C3D252      ; Color: Blue
         LDY #C3D2AB     ; Text pointer
         JSR C30326      ; Draw "Bat Pwr"
         JMP C3D24D      ; Color: User's
                         ; For Owned, etc.

; Compute buy order value
C3CAAA:  TDC             ; Clear A
         LDA $4B         ; Item slot
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $7E9F09,X   ; Price asked
         BRA C3CAD8      ; Price x size

; Compute sell order value
C3CABC:  JSR C3CF26      ; Selected item
         JSR C38AA2      ; Compute index
         REP #$20        ; 16-bit A
         LDA $D8501C,X   ; Base price
         LSR A           ; Halve it

; Compute buy or sell order value
C3CAD8:  SEP #$20        ; 8-bit A
         PHY             ; Save Y
         TAY             ; Item value
         LDA $28         ; Item quantity
         JSR mul16       ; Value x size
         STX $F1         ; Set total LBs
         STA $F3         ; Set total HB
         PLY             ; Restore Y
C3CB04:  RTS

; Draw buy order size and value
C3CB05:  JSR C3CB17      ; Draw order size
         JSR C3CAAA      ; Get order value
         BRA C3CB2E      ; Draw order value

; Draw sell order size and value
C3CB0E:  JSR C3CB17      ; Draw order size
         JSR C3CABC      ; Get order value
C3CB2E:  JSR C30605      ; Turn into text
         LDX #$7AA1      ; Text position
         JMP C3052F      ; Draw 7 digits

; Draw traded item's quantity and "GP" below
C3CB17:  JSR C3D252      ; Color: Blue
         LDY #C3D290     ; Text pointer
         JSR C30326      ; Draw "GP"
         JSR C3D24D      ; Color: User's
         LDA $28         ; Order size
         JSR C30563      ; Turn into text
         LDX #$7A2B      ; Text position
         JMP C30539      ; Draw 2 digits

; Initialize cursor data and draw inventory for Sell menu
C3CB37:  LDA #$01        ; 64x32 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$76        ; Top row: 119th
         STA $5C         ; Set scroll limit
         LDX #$020A      ; Onscreen rows: 10
         STX $5A         ; Onscreen cols: 2
         JSR C384A3      ; Load navig data
         LDY $4D         ; Cursor position
         STY $4F         ; Set as list loc
         LDA $4A         ; Scroll position
         CLC             ; Prepare ADC
         ADC $50         ; Add list V-Slot
         STA $50         ; Set list V-Slot
         JSR C384AC      ; Relocate cursor
C3CB59:  JSR C385BC      ; Draw inventory
C3CB5_:  LDA #$58        ; Y: 88
         LDY #$00EA      ; V-Speed: 0.914 px
         JMP C309A4      ; Create scrollbar

; Compile quantity owned of each item in Buy menu
C3CBB2:  LDX #$9DC9      ; 7E/9DC9
         STX $2181       ; Set WRAM LBs
         TDC             ; Clear A
         TAX             ; Menu slot: 1
C3CBBA:  LDY $00         ; Stock slot: 1
         LDA $7E9D89,X   ; Shop item
C3CBC1:  CMP $1869,Y     ; In stock slot?
         BEQ C3CBD1      ; Branch if so
         INY             ; Stock slot +1
         CPY #$0100      ; Done all 256?
         BNE C3CBC1      ; Loop if not
         TDC             ; Quantity: 0
         BRA C3CBD4      ; Skip a line
C3CBD1:  LDA $1969,Y     ; Quantity owned
C3CBD4:  STA $2180       ; Set shop item's
         INX             ; Menu slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3CBBA      ; Loop if not
         RTS

; Load and draw quantity owned of item in Buy menu
C3CBDF:  JSR C3CBED      ; Define $64
C3CBE2:  LDA $64         ; Quantity owned
         JSR C30563      ; Turn into text
         LDX #$7B3F      ; Text position
         JMP C30539      ; Draw 2 digits

; Get quantity owned of item in Buy menu
C3CBED:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9DC9,X   ; Quantity owned
         STA $64         ; Set as current
         RTS

; Load and draw quantity owned of item in Sell menu
C3CBF8:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1969,Y     ; Item quantity
         STA $64         ; Memorize it
         BRA C3CBE2      ; Draw quantity

; Count and draw quantity worn of item in Buy menu
C3CC03:  JSR C3CF1D      ; Item in slot
         JMP C3CEC4      ; Draw quantity

; Get sign found by actor for shop item
C3CC09:  STA $E0         ; Save actor slot
         JSR C3CC24      ; Actor can use?
         BCC C3CC22      ; No sign if not
         TDC             ; Clear A
         LDA $4B         ; Cursor slot
         JSR x16         ; x16
         ADC $E0         ; Add char slot
         TAX             ; Index sum
         LDA $AA8D,X     ; Sign
         RTS             ; Exit
C3CC22:  TDC             ; Sign: None
         RTS

; Check whether actor can equip shop item
C3CC24:  STZ $11D8       ; No Merit Award
         TAX             ; Index actor
         LDA $9E09,X     ; Actor in slot
         JSR C3A437      ; Define compat
         JSR C3CF1D      ; Item
         JSR C38AA2      ; Compute index
         REP #$20        ; 16-bit A
         LDA $D85001,X   ; Compatibility
         AND $E7         ; Actor can use?
         SEP #$20        ; 8-bit A
         BEQ C3CC55      ; Branch if not
         SEC             ; Mark success
         RTS             ; Exit
C3CC55:  CLC             ; Mark failure
         RTS

; Build sign list for each item in Buy menu
C3CC58:  LDX #$AA8D      ; 7E/AA8D
         STX $F3         ; Save WRAM adr
         LDY #$0080      ; 8 items x 16
         JSR clr_ram     ; Clear sign list
         LDX $00         ; Item slot: 1
C3CC62:  LDY $F3         ; WRAM address
         STY $2181       ; Set WRAM LBs
         PHX             ; Save item slot
         LDA $7E9D89,X   ; Item in slot
         STA $9F         ; Memorize it
         JSR C38AA2      ; Compute index
         LDA $D85014,X   ; Item's power
         STA $9E         ; Memorize it
         JSR itm_cl2     ; Item class
         ASL A           ; Double it
         TAX             ; Index it
         JSR (signtbl,X) ; Build list
         REP #$21        ; 16-bit A; C-
         LDA $F3         ; WRAM address
         ADC #$0010      ; Reach next item
         STA $F3         ; Save changes
         SEP #$20        ; 8-bit A
         PLX             ; Item slot
         INX             ; Item slot +1
         CPX #$0008      ; Done 8 items?
         BNE C3CC62      ; Loop if not
         RTS

; Jump table for the above
signtbl: dw C3CE65       ; Tool
         dw C3CD00       ; Weapon
         dw C3CCA0       ; Armor
         dw C3CD90       ; Shield
         dw C3CE18       ; Helmet
         dw C3CE73       ; Relic
         dw C3CE65       ; Consumable

; Build sign list for weapon
C3CD00:  LDX $00         ; 1st: Terra
C3CD02:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C3CD82      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAX             ; Index in X
         TAY             ; Index in Y
         SEP #$20        ; 8-bit A

; Fork: Check if holding shop item
C3CD15:  LDA $9F         ; Shop item
         CMP $1F,X       ; In R-Hand?
         BEQ C3CD79      ; Use "E" if so
         CMP $20,X       ; In L-Hand?
         BEQ C3CD79      ; Use "E" if so

; Fork: Check if weapon in R-Hand
C3CD23:  LDA $001F,X     ; R-Hand item
         CMP #$FF        ; None?
         BEQ C3CD3B      ; Branch if so
         JSR itm_cl1     ; Item class
         DEC A           ; Weapon?
         BEQ C3CD59      ; Branch if so

; Fork: No weapon in R-Hand, check L-Hand
C3CD3B:  LDA $0020,Y     ; L-Hand item
         CMP #$FF        ; None?
         BEQ C3CD71      ; Use "^" if so
         JSR itm_cl1     ; Item class
         DEC A           ; Weapon?
         BNE C3CD59      ; Branch if not
         LDA $0020,Y     ; L-Hand item
         BRA C3CD5D      ; Compare power

; Fork: Compare weapons' power
C3CD59:  LDA $001F,Y     ; R-Hand item
C3CD5D:  CMP #$FF        ; None?
         BEQ C3CD71      ; Use "^" if so
         JSR C38AA2      ; Compute index
         LDA $D85014,X   ; Item's Bat.Pwr
         CMP $9E         ; Matches shop's?
         BEQ C3CD7D      ; Use "=" if so
         BCS C3CD75      ; Use "v" if above
C3CD71:  LDA #$02        ; Sign: "^"
         BRA C3CD7F      ; Add to list

; Fork: Use "v" sign for weapon
C3CD75:  LDA #$03        ; Sign: "v"
         BRA C3CD7F      ; Add to list

; Fork: Use "E" sign for weapon
C3CD79:  LDA #$01        ; Sign: "E"
         BRA C3CD7F      ; Skip a line

; Fork: Use "=" sign for weapon
C3CD7D:  LDA #$04        ; Sign: "="
C3CD7F:  STA $2180       ; Add to list
C3CD82:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3CD02      ; Loop if not
         RTS

; Build sign list for shield
C3CD90:  LDX $00         ; 1st: Terra
C3CD92:  PHX             ; Save actor index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C3CE0A      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A

; Fork: Check if holding shop item
C3CDA5:  LDA $9F         ; Shop item
         CMP $001F,Y     ; In R-Hand?
         BEQ C3CE01      ; Use "E" if so
         CMP $0020,Y     ; In L-Hand?
         BEQ C3CE01      ; Use "E" if so

; Fork: Check if holding a shield
C3CDB3:  LDA $0020,Y     ; L-Hand item
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BEQ C3CDE1      ; Branch if so
         LDA $001F,Y     ; R-Hand item
         JSR itm_cl1     ; Item class
         CMP #$03        ; Shield?
         BNE C3CDF9      ; Use "^" if not
         LDA $001F,Y     ; R-Hand item
         BRA C3CDE5      ; Compare defense

; Fork: Compare shields' defense
C3CDE1:  LDA $0020,Y     ; L-Hand item
C3CDE5:  CMP #$FF        ; None?
         BEQ C3CDF9      ; Use "^" if so
         JSR C38AA2      ; Compute index
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3CE05      ; Use "=" if so
         BCS C3CDFD      ; Use "v" if above
C3CDF9:  LDA #$02        ; Sign: "^"
         BRA C3CE07      ; Add to list

; Fork: Use "v" sign for shield
C3CDFD:  LDA #$03        ; Sign: "v"
         BRA C3CE07      ; Add to list

; Fork: Use "E" sign for shield
C3CE01:  LDA #$01        ; Sign: "E"
         BRA C3CE07      ; Skip a line

; Fork: Use "=" sign for shield
C3CE05:  LDA #$04        ; Sign: "="
C3CE07:  STA $2180       ; Add to list
C3CE0A:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3CD92      ; Loop if not
         RTS

; Build sign list for armor
C3CCA0:  LDA #$01        ; Point to armor
         BRA C3CE1_      ; Skip a line

; Build sign list for helmet
C3CE18:  TDC             ; Point to helmet
C3CE1_:  STA $FF         ; Set address mod
         LDX $00         ; 1st: Terra
C3CE1A:  PHX             ; Save char index
         REP #$21        ; 16-bit A; C-
         LDA $1EDC       ; Shown actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C3CE5A      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         ADC $FF         ; +1 if armor slot
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $21,X       ; Armor or helmet
         CMP $9F         ; In shop slot?
         BEQ C3CE51      ; Use "E" if so
         CMP #$FF        ; None?
         BEQ C3CE49      ; Use "^" if so
         JSR C38AA2      ; Compute index
         LDA $D85014,X   ; Item's defense
         CMP $9E         ; Matches shop's?
         BEQ C3CE55      ; Use "=" if so
         BCS C3CE4D      ; Use "v" if above
C3CE49:  LDA #$02        ; Sign: "^"
         BRA C3CE57      ; Add to list

; Fork: Use "v" sign for armor or helmet
C3CE4D:  LDA #$03        ; Sign: "v"
         BRA C3CE57      ; Add to list

; Fork: Use "E" sign for armor or helmet
C3CE51:  LDA #$01        ; Sign: "E"
         BRA C3CE57      ; Skip a line

; Fork: Use "=" sign for armor or helmet
C3CE55:  LDA #$04        ; Sign: "="
C3CE57:  STA $2180       ; Add to list
C3CE5A:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3CE1A      ; Loop if not
         RTS

; Clear sign list for consumable or tool
C3CE65:  LDA #$10        ; Actors: 16
C3CE67:  STZ $2180       ; Clear a sign
         DEC A           ; One less left
         BNE C3CE67      ; Loop till last
         RTS

; Build sign list for relic
C3CE73:  TDC             ; Clear A
         TAX             ; 1st: Terra
C3CE75:  PHX             ; Save char index
         REP #$20        ; 16-bit A
         LDA $1EDC       ; Shown actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C3CE9F      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $9F         ; Shop item
         CMP $23,X       ; In relic slot 1?
         BEQ C3CE9A      ; Use "E" if so
         CMP $24,X       ; In relic slot 2?
         BEQ C3CE9A      ; Use "E" if so
         TDC             ; Sign: None
         BRA C3CE9C      ; Skip a line
C3CE9A:  LDA #$01        ; Sign: "E"
C3CE9C:  STA $2180       ; Add to list
C3CE9F:  PLX             ; Actor index
         INX             ; Index +1
         INX             ; Index +1
         CPX #$0020      ; Done 16 chars?
         BNE C3CE75      ; Loop if not
         RTS

; Count and draw quantity worn of item in Sell menu
C3CEC1:  JSR C3CF26      ; Selected item
C3CEC4:  STA $E0         ; Memorize it
         STZ $65         ; Quantity worn: 0
         LDX #$161F      ; 00/161F
         STX $E7         ; Set address LBs
         STZ $E9         ; Address HB: 00
         LDX $00         ; 1st: Terra
C3CED3:  PHX             ; Save actor slot
         REP #$20        ; 16-bit A
         TXA             ; Get actor
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Eligible actors
         AND.L C3A456,X  ; Has our actor?
         BEQ C3CF00      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA $00,X       ; Actor
         CMP #$0E        ; Guest?
         BCS C3CF00      ; Skip if so
         LDY $00         ; 1st: R-Hand
C3CEF2:  LDA [$E7],Y     ; Equipped item
         CMP $E0         ; Matches shop's?
         BNE C3CEFA      ; Branch if not
         INC $65         ; Quantity worn +1
C3CEFA:  INY             ; Gear slot +1
         CPY #$0006      ; Done all 6?
         BNE C3CEF2      ; Loop if not
C3CF00:  REP #$21        ; 16-bit A; C-
         LDA #$0025      ; Actor data size
         ADC $E7         ; Add SRAM pointer
         STA $E7         ; Set SRAM pointer
         SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Point to next
         CPX #$0010      ; Done all 16?
         BNE C3CED3      ; Loop if not
         LDA $65         ; Quantity worn
         JSR C30563      ; Turn into text
         LDX #$7C3F      ; Text position
         JMP C30539      ; Draw 2 digits

; Get list entry by cursor
C3CF1D:  TDC             ; Clear A
         LDA $4B         ; Cursor slot
         TAX             ; Index it
         LDA $7E9D89,X   ; Item in slot
         RTS

; Get inventory item by cursor
C3CF26:  TDC             ; Clear A
         LDA $4B         ; List slot
         TAY             ; Index it
         LDA $1869,Y     ; Item in slot
         RTS

; Draw shop title and define shop index
C3CF2E:  JSR C3D252      ; Color: Blue
C3CF31:  LDA $0201       ; Shop number
         XBA             ; Put in B
         LDA #$09        ; Shop data size
         JSR mul8        ; Number x size
         TAX             ; Index product
         STX $67         ; Set shop index
         TDC             ; Clear A
         LDA $C47AC0,X   ; Shop flags
         AND #$07        ; Title number
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3CF67-2,X; Text pointer
         TAY             ; Set src LBs
         JMP C30326      ; Draw title

; Pointers to shop titles
C3CF67:  dw C3D257       ; Weapon
         dw C3D25D       ; Armor
         dw C3D264       ; Item
         dw C3D26B       ; Relics
         dw C3D275       ; Vendor

; Load item's name
C3CFC3:  JSR C3CFC_      ; Load name
         STZ $2180       ; End string
         RTS

; Load item's name without ending string
C3CFC_:  XBA             ; Put item in B
         LDX.W #!itm_ns  ; Letters: 9
         LDA.B #!itm_np!h; Text ptr HB
         LDY.W #!itm_np  ; Text ptr LBs
         JMP fw_txt      ; Load name

; Compile and create actors for Buy menu
C3CFF5:  JSR C3D064      ; Compile actors
         JSR C3D127      ; Mark members
         TDC             ; Clear A
         TAX             ; List slot: 1
C3CFFD:  LDA $7E9E09,X   ; Actor in slot
         BMI C3D09B      ; Exit if none
         PHX             ; Save slot
         PHA             ; Save actor
         LDY #C3D09C     ; C3/D09C
         JSR qanim2      ; Queue OAM fn
         TXY             ; Queue slot
         TDC             ; Clear A
         PLA             ; Actor
         STA $7E35C9,X   ; Link to OBJ
         JSR C3808E      ; Set anim ptr
         PLX             ; List slot
         LDA.L C3D048,X  ; X position
         STA $33CA,Y     ; Set actor's
         LDA.L C3D056,X  ; Y position
         STA $344A,Y     ; Set actor's
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         INX             ; List slot +1
         BRA C3CFFD      ; Do next char

; Compile actors for Buy menu
C3D064:  LDX #$9E09      ; 7E/9E09
         STX $2181       ; Set WRAM LBs
         LDX $00         ; 1st: Terra
C3D06C:  PHX             ; Save char slot
         REP #$20        ; 16-bit A
         TXA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA $1EDC       ; Showable chars
         AND.L C3A456,X  ; Has our actor?
         BEQ C3D08D      ; Skip if not
         LDA.L C370DB,X  ; Actor's address
         TAY             ; Index it
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor
         CMP #$0E        ; Guest?
         BCS C3D08D      ; Skip if so
         STA $2180       ; Add to list
C3D08D:  SEP #$20        ; 8-bit A
         PLX             ; Actor slot
         INX             ; Slot +1
         CPX #$0010      ; Done all 16?
         BNE C3D06C      ; Loop if not
         LDA #$FF        ; Terminator
         STA $2180       ; End list
C3D09B:  RTS

; Update shop actor
C3D09C:  BNE C3D0C5      ; If mode 1

; Mode 0: Initialize data
C3D0A4:  LDA #$01        ; Hide actors: N
         TSB $47         ; Set menu flag
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA $32C9,X     ; Anim table ptr
         STA $34CA,X     ; Save original
         JSR C31271      ; Set pose timer
;        LDA $47         ; Menu flags
;        AND #$08        ; Shop mode?...
;        BNE C3D0C5      ; Branch if not
         JSR C3D14B      ; Create big arrow

; Mode 1: Sustain sprite
C3D0C5:  LDA $47         ; Menu flags
         LSR A           ; Remove actors?
         BCC C3D0F5      ; Delete if so
         LDX $2D         ; Queue index
         LDA $47         ; Menu flags
         AND #$08        ; Shop mode?...
         BNE C3D0E4      ; Branch if not
         LDA $35C9,X     ; Actor
         JSR C3CC24      ; Waving arms?
         LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         BCC C3D0E4      ; If not waving
         LDA $34CA,X     ; Base anim ptr
         CLC             ; Prepare ADC
         ADC #$0009      ; Adjust value
         BRA C3D0EB      ; Set real ptr
C3D0E4:  LDA $34CA,X     ; Base anim ptr
C3D0EB:  STA $32C9,X     ; Set as current
         JMP oamsec      ; Set OAM; requeue
C3D0F5:  CLC             ; Set to dequeue
         RTS

; Compile party members for Buy menu
C3D127:  LDX #$9E01      ; 7E/9E01
         STX $2181       ; Set WRAM LBs
         LDY $00         ; Member index: 0
C3D12F:  LDX $6D,Y       ; Actor's address
         BEQ C3D13E      ; Skip if nobody
         LDA $00,X       ; Actor in slot
         BRA C3D140      ; Skip a line
C3D13E:  LDA #$FF        ; Actor: None
C3D140:  STA $2180       ; Add to list
         INY             ; Member index +1
         INY             ; Member index +1
         CPY #$0008      ; Done 4 members?
         BNE C3D12F      ; Loop if not
         RTS

; Create arrow under shop actor if in party
C3D14B:  LDY #$0003      ; Member slot: 4
C3D14F:  LDA $35C9,X     ; Shop actor
         CMP $9E01,Y     ; In member slot?
         BNE C3D18F      ; Try next if not
         PHX             ; Save queue index
         PHY             ; Save member slot
         LDY #C382C9     ; C3/82C9
         JSR qanim0      ; Queue OAM fn
         JSR db7e        ; Set DB to 7E
         LDA #$D8        ; Anim ptr HB
         LDY #$EC33      ; Anim ptr LBs
         JSR anm_st      ; Set arrow's
         LDY $374A,X     ; Actor's index
         LDA $33CA,Y     ; Actor's X
         STA $33CA,X     ; Set arrow's
         LDA $344A,Y     ; Actor's Y
         DEC A           ; +1 px up
         DEC A           ; +1 px up
         STA $344A,X     ; Set arrow's Y
         PLY             ; Member slot
         PLX             ; Queue index
C3D18F:  DEY             ; Member slot -1
         BPL C3D14F      ; Loop till last
         RTS

; Create sign by each actor in Buy menu
C3D196:  TDC             ; Clear A
         TAY             ; Char slot: 1
C3D198:  PHY             ; Save char slot
         LDA #$04        ; Min slot: 32
         LDY #C3D1AE     ; C3/D1AE
         JSR C311DE      ; Queue OAM fn
         PLY             ; Char slot
         TYA             ; Put in A
         STA $7E35C9,X   ; Assign to sign
         INY             ; Char slot +1
         CPY #$000E      ; Done all 14?
         BNE C3D198      ; Loop if not
         RTS

; Update shop sign
C3D1AE:  BNE C3D1E6      ; If mode 1

; Mode 0: Initialize sprite
C3D1B6:  LDA #$D8        ; Anim ptr HB
         LDY #$EC57      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         REP #$20        ; 16-bit A
;        TYA             ; Anim table ptr
         STA $34CA,X     ; Set original
         SEP #$20        ; 8-bit A
         INC $3649,X     ; Mode +1
         TDC             ; Clear A
         LDA $35C9,X     ; Char slot
         TXY             ; Queue index
         TAX             ; Index slot
         LDA $D8EC3B,X   ; X position
         STA $33CA,Y     ; Set sign's
         LDA $D8EC49,X   ; Y position
         STA $344A,Y     ; Set sign's
         JSR C3127_      ; Set pose timer

; Mode 1: Sustain sprite
C3D1E6:  LDA $47         ; Menu flags
         LSR A           ; Actors shown?
         BCC C3D23A      ; Delete if not
         TDC             ; ...
         LDA $35C9,X     ; Char slot
         JSR C3CC09      ; Sign
         BEQ C3D238      ; Exit if none
         REP #$21        ; 16-bit A; C-
         LDX $2D         ; Queue index
         DEC A           ; Equipped?
         BEQ C3D211      ; Branch if so
         DEC A           ; Up?
         BEQ C3D226      ; Branch if so
         DEC A           ; Down?
         BEQ C3D205      ; Branch if so

; Fork: Equal sign
C3D21A:  LDA $34CA,X     ; Base anim ptr
         ADC #$0024      ; Adjust value
         BRA C3D230      ; Set real ptr

; Fork: Equipped sign
C3D211:  LDA $34CA,X     ; Base anim ptr
         BRA C3D230      ; Set as current

; Fork: Down sign
C3D205:  LDA $34CA,X     ; Base anim ptr
         ADC #$0018      ; Adjust value
         BRA C3D230      ; Set real ptr

; Fork: Up sign
C3D226:  LDA $34CA,X     ; Base anim ptr
         ADC #$000C      ; Adjust value
C3D230:  STA $32C9,X     ; Set real ptr
         JSR C3128C      ; Define OAM
C3D238:  SEC             ; Set to requeue
         RTS

; Fork: Delete sign
C3D23A:  CLC             ; Set to dequeue
         RTS

; Draw "Owned:" and "Equipped:" for Buy menu
C3D23C:  JSR C3D252      ; Color: Blue
         LDY #C3D295     ; Text pointer
         JSR C30326      ; Draw "Owned:"
         LDY #C3D29F     ; Text pointer
         JSR C30326      ; Draw "Equipped:"

; Set text color to player's color
C3D24D:  LDA #$20        ; Palette 0
         BRA st_29       ; Color: User's

; Set text color to blue
C3D252:  LDA #$2C        ; Palette 3
         BRA st_29       ; Color: Blue

; Set text color to blue or gray
txt30:   LDA #$30        ; Palette 4
st_29:   STA $29         ; Color: Gray
         RTS

; =============================================================================

; Jump table for ending sequences
C3D375:  dw C3D52D       ; 00: Fade screen before ending scene
         dw C3D543       ; 01: Return to event script
         dw C3D7DB       ; 02: Show aerial-view panning clouds
         dw C3D81B       ; 03: Wait before fading screen
         dw C3D822       ; 04: Show spinning clouds
         dw C3D550       ; 05: Start sideview airship scene
         dw C30000       ; 06: Unused...
         dw C30000       ; 07: Unused...
         dw C30000       ; 08: Unused...
         dw C3D706       ; 09: Start aerial-view airship scene
         dw C3D744       ; 0A: Show aerial-view airship
         dw C3D753       ; 0B: Fade screen to white
         dw C3D849       ; 0C: Start boat scene
         dw C3D88F       ; 0D: Show boat sprite
         dw C30000       ; 0E: Unused...
         dw C30000       ; 0F: Unused...
         dw C3D945       ; 10: Start skimming airship scene
         dw C3DA07       ; 11: Show swooping bird
         dw C30000       ; 12: Unused...
         dw C30000       ; 13: Unused...
         dw C3DC92       ; 14: Start frontview airship scene
         dw C3DD1E       ; 15: Show late bird flock
         dw C30000       ; 16: Unused...
         dw C30000       ; 17: Unused...
         dw C3DE24       ; 18: Start aerial-view plains scene
         dw C30000       ; 19: Unused...
         dw C30000       ; 1A: Unused...
         dw C30000       ; 1B: Unused...
         dw C3DE6D       ; 1C: Start rearview airship scene
         dw C30000       ; 1D: Unused...
         dw C30000       ; 1E: Unused...
         dw C30000       ; 1F: Unused...
         dw C3DFB3       ; 20: Start final airship scene
         dw C3E01A       ; 21: Fade final airship
         dw C30000       ; 22: Unused...
         dw C30000       ; 23: Unused...
         dw C30000       ; 24: Unused...
         dw C30000       ; 25: Unused...
         dw C30000       ; 26: Unused...
         dw C30000       ; 27: Unused...
         dw C3F1A8       ; 28: Start Shadow's scene
         dw C3F1EC       ; 29: Fade in "Shadow as"
         dw C3F1FB       ; 2A: Switch Shadow's names
         dw C3F20A       ; 2B: Fade all but Shadow's name
         dw C30000       ; 2C: Unused...
         dw C3F608       ; 2D: Start first book scene
         dw C3F619       ; 2E: Animate first book
         dw C3F628       ; 2F: Wait 480 frames
         dw C3F634       ; 30: Pixelate and fade first book
         dw C30000       ; 31: Unused...
         dw C3F232       ; 32: Start Cyan's scene
         dw C3F253       ; 33: Fade in "Cyan as"
         dw C3F262       ; 34: Switch Cyan's names
         dw C3F271       ; 35: Fade all but Cyan's name
         dw C30000       ; 36: Unused...
         dw C30000       ; 37: Unused...
         dw C3F221       ; 38: Fade actor's true name
         dw C30000       ; 39: Unused...
         dw C30000       ; 3A: Unused...
         dw C30000       ; 3B: Unused...
         dw C3F31B       ; 3C: Start Mog's scene
         dw C3F337       ; 3D: Fade in "Mog as"
         dw C3F346       ; 3E: Switch Mog's names
         dw C3F355       ; 3F: Fade all but Mog's name
         dw C3F285       ; 40: Start Edgar and Sabin's scene
         dw C3F29E       ; 41: Fade in "Edgar as"
         dw C3F2AD       ; 42: Switch Edgar's names
         dw C3F2BC       ; 43: Show Sabin's name, fade Edgar's
         dw C3F2DC       ; 44: Delete Edgar's name
         dw C3F2EC       ; 45: Switch Sabin's names
         dw C3F36C       ; 46: Start Gogo's scene
         dw C3F393       ; 47: Fade in "Gogo as"
         dw C3F3B6       ; 48: Switch Gogo's names
         dw C3F3C5       ; 49: Fade all but Gogo's name
         dw C3F64B       ; 4A: Start last book scene
         dw C3F664       ; 4B: Wait 180 frames
         dw C3F670       ; 4C: Stop last book and fade in text
         dw C3F683       ; 4D: Pixelate and fade last book
         dw C30000       ; 4E: Unused...
         dw C3F307       ; 4F: Fade all but Sabin's name
         dw C3F434       ; 50: Start Gau's scene
         dw C3F44D       ; 51: Fade in "Gau as"
         dw C3F45C       ; 52: Switch Gau's names; create face
         dw C3F46E       ; 53: Fade all but Gau's name
         dw C30000       ; 54: Unused...
         dw C30000       ; 55: Unused...
         dw C30000       ; 56: Unused...
         dw C30000       ; 57: Unused...
         dw C30000       ; 58: Unused...
         dw C30000       ; 59: Unused...
         dw C3F485       ; 5A: Start Terra's scene
         dw C3F49E       ; 5B: Fade in "Terra as"
         dw C3F4AD       ; 5C: Switch Terra's names, create glint
         dw C3F4BF       ; 5D: Fade all but Terra's name
         dw C30000       ; 5E: Unused...
         dw C30000       ; 5F: Unused...
         dw C30000       ; 60: Unused...
         dw C30000       ; 61: Unused...
         dw C30000       ; 62: Unused...
         dw C30000       ; 63: Unused...
         dw C3F4D6       ; 64: Start Locke and Celes's scene
         dw C3F4F1       ; 65: Fade in "Locke as"
         dw C3F500       ; 66: Switch Locke's names
         dw C3F50F       ; 67: Show Celes's name, fade Locke's
         dw C3F52F       ; 68: Delete Locke's name
         dw C3F53F       ; 69: Switch Celes's names
         dw C3F558       ; 6A: Fade all but Celes's name
         dw C30000       ; 6B: Unused...
         dw C30000       ; 6C: Unused...
         dw C30000       ; 6D: Unused...
         dw C3F56F       ; 6E: Start Relm's scene
         dw C3F58B       ; 6F: Fade in "Relm as"
         dw C3F59A       ; 70: Switch Relm's names
         dw C3F5A9       ; 71: Fade all but Relm's name
         dw C30000       ; 72: Unused...
         dw C30000       ; 73: Unused...
         dw C30000       ; 74: Unused...
         dw C30000       ; 75: Unused...
         dw C30000       ; 76: Unused...
         dw C30000       ; 77: Unused...
         dw C3F5C0       ; 78: Start Strago's scene
         dw C3F5D6       ; 79: Fade in "Strago as"
         dw C3F5E5       ; 7A: Switch Strago's names
         dw C3F5F4       ; 7B: Fade all but Strago's name
         dw C30000       ; 7C: Unused...
         dw C30000       ; 7D: Unused...
         dw C30000       ; 7E: Unused...
         dw C30000       ; 7F: Unused...
         dw C30000       ; 80: Unused...
         dw C30000       ; 81: Unused...
         dw C3F697       ; 82: Start Setzer's scene
         dw C3F6CE       ; 83: Fade in "Setzer as"
         dw C3F6DD       ; 84: Switch Setzer's names
         dw C3F6EC       ; 85: Fade background
         dw C3F6FB       ; 86: Fade cards and name
         dw C3F71F       ; 87: Start Umaro's scene
         dw C3F73E       ; 88: Fade in "Umaro as"
         dw C3F74D       ; 89: Switch Umaro's names
         dw C3F75C       ; 8A: Fade all but Umaro's name

; Display requested ending cinematic
C3D48B:  PHP             ; Push PS
         REP #$30        ; 16-bit A, X, Y
         PHY             ; Push Y
         PHB             ; Push DB
         PHD             ; Push DP
         SEP #$20        ; 8-bit A
         PEI ($00)       ; Push #$0000
         PLD             ; Set DP to 0
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         JSR C300C0      ; Reroute NMI/IRQ
         JSR C3706C      ; Reset variables
         LDY #$012C      ; Scroll delay: 300
         STY $85         ; For true char name
         STZ $B4         ; Blue credits: N
         LDY $00         ; Scene timer: 0
         STY $CF         ; Set for text
         JSR C3D4F5      ; Stop VRAM DMA
         JSR C3D4E5      ; Disable pad, etc.
         JSL $D4CD48     ; Init registers
;        JSL C3AC4F      ; Init joypad...
         JSR C3117F      ; Reset OAM, queue
         JSR C3ECC3      ; Clear VRAM
         JSL $D4CF3B     ; Back up data
         LDA $0201       ; Event parameter
         STA $26         ; Set scene mode
         JSR C3D514      ; Handle scene
         JSL $D4CF4B     ; Restore backup
         JSR C3D4E5      ; Disable pad, etc.
         REP #$30        ; 16-bit A, X, Y
         PLD             ; Pull DP
         PLB             ; Pull DB
         PLY             ; Pull Y
         PLP             ; Pull PS
         RTL

; Disable screen, interrupts, joypad, and HDMA
C3D4E5:  LDA #$8F        ; BRT: 15 and OFF
         STA $2100       ; Disable screen
         STZ $4200       ; Disable INT, pad
         STZ $420C       ; Disable HDMA
         RTS

; Reset variables for automatic uploads during NMI
C3D4F5:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $1B         ; Halt VRAM B
         STY $1D         ; Clear src-B LBs
         STA $1F         ; Clear src-B HB
         STY $16         ; Clear src-A LBs
         STA $18         ; Clear src-A HB
         INY             ; Bytes: 1
         STY $19         ; Set data size B
         STY $12         ; Set data size A
         LDY #$7FFF      ; $7FFF
         STY $14         ; Set VRAM ptr A
         RTS

; Enable color addition on BG1
C3D50E:  LDA #$01        ; BG1: ADD mode
         STA $2131       ; Set register
C3D513:  RTS

; Handle ending sequence
C3D514:  TDC             ; Clear A
         LDA $26         ; Scene mode
         CMP #$FF        ; Exit to map?
         BEQ C3D513      ; Exit if so
         REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         JSR (C3D375,X)  ; Handle mode
         JSR C3121B      ; Run anim queue
         JSR C313D3      ; Refresh screen
         BRA C3D514      ; Loop

; 00: Fade screen before ending scene
C3D52D:  LDY $20         ; Delay expired?
         BNE C3D513      ; Exit if not
         INC $26         ; Next: Exit
         LDA #$0F        ; Frames: 15
         STA $20         ; Set exit delay
         LDY #C3E181     ; C3/E181
         JMP qanim0      ; Queue fade-out

; 01: Return to event script after delay
C3D543:  LDY $20         ; Delay expired?
         BNE C3D513      ; Exit if not
;        BRA C3F1A3      ; End scene

; Set to return to event script
C3F1A3:  LDA #$FF        ; Null value
         STA $26         ; Next: Exit
         RTS

; Set text for credits to be blue
C3D54B:  LDA #$01        ; Blue text: Y
         STA $B4         ; Set color mode
         RTS

; 05: Start sideview airship scene
C3D550:  JSR C3D54B      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3E39C      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CBFC     ; Queue HDMA 1-7
         LDY #$0010      ; Zoom-out: 16
         STY $8E         ; Set for airship
         REP #$20        ; 16-bit A
         LDA #$FFF1      ; H-Scroll: -15
         STA $7EB68D     ; Set for airship
         LDA #$002E      ; V-Scroll: 46
         STA $7EB68F     ; Set for airship
         LDA #$0071      ; Center X: 113
         STA $7EB695     ; Set for airship
         LDA #$008D      ; Center Y: 141
         STA $7EB697     ; Set for airship
         SEP #$20        ; 8-bit A
         LDY #$005E      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$2F00      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$0100      ; Center X: 256
         STY $B7         ; Set for clouds
         LDY #$0311      ; Center Y: 785
         STY $B9         ; Set for clouds
         LDY #$0080      ; BG1's X: 128
         STY $35         ; Set for clouds
         LDY #$0291      ; BG1's Y: 657
         STY $37         ; Set for clouds
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         JSR C3E8C8      ; Build text OAM
         LDY #C3E71E     ; C3/E71E
         JSR qanim2      ; Queue credits
         LDY #C3D5F3     ; C3/D5F3
         JSR qanim2      ; Queue M7 anim
         LDY #C3E076     ; C3/E076
         JSR qanim0      ; Queue rotor anim
         JSR C3E0E0      ; Make text black
         JSR C3E0F7      ; Load cloud colors
         JSR C3DF9C      ; Load sky/plane's
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Fade-out
         LDY #$021C      ; Frames: 540
         STY $20         ; Set fade delay

; Queue field fade-in
C3D5DE:  LDY #C3E150     ; C3/E150
         JMP qanim0      ; Queue fade-in

; Set brightness before fading in colors manually
C3D5E7:  LDA #$01        ; BRT: 1 and ON
         STA $44         ; Set brightness
         JSR C313D3      ; Refresh screen
         LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         RTS

; Shrink sideview airship and scroll clouds
C3D5F3:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         REP #$20        ; 16-bit A
         BCS C3D618      ; Branch if odd
         INC $8E         ; Matrix A +1
C3D618:  LDA $8E         ; Matrix A
         STA $0600       ; Set for airship
         STZ $07C2       ; Matrix B: 0
         STZ $0984       ; Matrix C: 0

; Fork: Scroll clouds
C3D631:  REP #$20        ; 16-bit A
         DEC $35         ; BG1's X -1
         DEC $B7         ; Center X -1
         LDA $35         ; BG1 X-Pos
         STA $B691       ; To HDMA table
         LDA $37         ; BG1 Y-Pos
         STA $B693       ; To HDMA table
         LDA $B7         ; Center X
         STA $B699       ; To HDMA table
         LDA $B9         ; Center Y
         STA $B69B       ; To HDMA table
         SEP #$21        ; 8-bit A; requeue
         RTS

; Set to fade credits
C3D64E:  JSR C3F1D8      ; Do big font
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #C3115F     ; Black palette
         JMP slow4       ; Do small font

; Set to fade in credits to white and blue
C3D675:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$974C      ; C2/974C
         JSR slow4       ; Do big font
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #$9744      ; C2/9744
         JMP slow4       ; Do small font

; Set to fade in credits to dark blue
C3D69C:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$973C      ; C2/973C
         JSR slow4       ; Do big font
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$31E9      ; To OBJ pal 5
         LDX #$9734      ; C2/9734
         JMP slow4       ; Do small font

; Load non-text sprite colors for Mode 7 scene
C3D6C3:  LDX #$97EC      ; C2/97EC
         LDY #$3149      ; To OBJ pal 0
         JSR C30FF9      ; Do balloon's
         LDX #$978C      ; C2/978C
         LDY #$3169      ; To OBJ pal 1
         JSR C30FF9      ; Do airships'
         LDX #$97AC      ; C2/97AC
         LDY #$3189      ; To OBJ pal 2
         JSR C30FF9      ; Do boat's
         LDX #$97CC      ; C2/97CC
         LDY #$31A9      ; To OBJ pal 3
         JSR C30FF9      ; Do cockpit's
         LDX #$982C      ; C2/982C
         LDY #$3209      ; To OBJ pal 6
         JSR C30FF9      ; Do gray birds'
         LDX #$980C      ; C2/980C
         LDY #$3229      ; To OBJ pal 7
         JMP C30FF9      ; Do spray's

; 09: Start aerial-view airship scene
C3D706:  JSR C3D54B      ; Blue text: Y
         JSL $D4CED7     ; Init registers
         JSR C3E487      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3D6C3      ; Load OBJ colors
         JSR C3E0E0      ; Make text black
         JSR C3E0F7      ; Load cloud colors
         LDY #$8A60      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue cloud anim
         JSR C3E8DE      ; Build text OAM
         LDY #C3E730     ; C3/E730
         JSR qanim2      ; Queue credits
         JSR C3E224      ; Queue M7 handler
         INC $26         ; Next: C3/D744
         LDY #$03C0      ; Frames: 960
         STY $20         ; Set plane delay
         JMP C3D5DE      ; Queue fade-in

; 0A: Show aerial-view airship and its shadow
C3D744:  LDY $20         ; Delay expired?
         BNE C3D7DA      ; Exit if not
         INC $26         ; Next: C3/D753
         LDY #$0870      ; Frames: 2160
         STY $20         ; Set fade delay
         BRA C3D774      ; Create sprites

; 0B: Fade screen to white
C3D753:  LDY $20         ; Delay expired?
         BNE C3D7DA      ; Exit if not
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Black out
         LDA #$78        ; Frames: 120
         STA $20         ; Set fade delay
         LDA #$C3        ; Bank: C3
         STA $ED         ; Set src HB
         LDY #$30A9      ; To BG pal 3
         LDX #C3113F     ; White palette
         JMP slow2       ; Whiten clouds

; Create aerial-view airship and its shadow
C3D774:  LDA #$C2        ; Anim ptr HB
         LDY #$8CCC      ; Anim ptr LBs
         LDX #$A0F8      ; Pos: 248, 160
         JSR C3D7B8      ; Create airship
         REP #$20        ; 16-bit A
         LDA #$8CCC      ; Ship anim ptr
         JSR C3D7C1      ; Set spd, timer
         LDY #C3EDD4     ; C3/EDD4
         JSR qanim3      ; Queue shadow fn
         JSR C3D7C1      ; Set spd, timer
         PEA $B0F8       ; Pos: 248, 176
         PEA $8CE0       ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3F90X      ; Set shadow's

; Queue linearly moving temporary sprite
C3D7B8:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3EDD4     ; C3/EDD4
         JSR qanim1      ; Queue OAM fn
         JMP C3F90X      ; Set pos, ptr

; Initialize data for aerial-view airship or its shadow
C3D7C1:  REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set sprite's
         LDA #$FFE0      ; V-Spd: -0.125 px
         STA $7E3549,X   ; Set sprite's
         LDA #$0400      ; Frames: 1024
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
C3D7DA:  RTS

; 02: Show aerial-view panning clouds
C3D7DB:  JSR C3D7F0      ; Load map, etc.
         LDY #$00F0      ; Frames: 240
         STY $20         ; Set fade delay
         LDY #$8B2C      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue cloud anim
         INC $26         ; Next: Fade-out
         JMP C3D5DE      ; Queue fade-in

; Initialize data for spinning or panning clouds
C3D7F0:  JSL $D4CED7     ; Init registers
         JSR C3E487      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         JSR C3D6C3      ; Load OBJ colors
         JSR C3E0E0      ; Make text black
         LDY #$0200      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         JSR C3E0F7      ; Load cloud colors
         JMP C3E224      ; Queue M7 handler

; 03: Wait before fading screen
C3D81B:  LDY $20         ; Delay expired?
         BNE C3D821      ; Exit if not
         STZ $26         ; Next: Fade-out
C3D821:  RTS

; 04: Show spinning clouds
C3D822:  JSR C3D7F0      ; Load map, etc.
         LDY #$8000      ; Vertical angle
         STY $C7         ; Set for clouds
         LDY #$8000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         LDY #$0078      ; Frames: 120
         STY $20         ; Set fade delay
         LDY #$8B32      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue cloud anim
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Fade-out
         JMP C3D5DE      ; Queue fade-in

; 0C: Start boat scene
C3D849:  JSL $D4CED7     ; Init registers
         JSR C3D50E      ; Color math: BG1
         JSR C3E50F      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3E0E0      ; Make text black
         JSR C3E0F7      ; Load BG1 colors
         JSR C3D6C3      ; Load OBJ colors
         LDY #$8AC9      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue sea anim
         JSR C3DA42      ; Create birds
         JSR C3E8F4      ; Build text OAM
         LDY #C3E77E     ; C3/E77E
         JSR qanim2      ; Queue credits
         JSR C3E224      ; Queue M7 handler
         LDY #$0438      ; Delay: 1080
         STY $20         ; Set boat OBJ's
         INC $26         ; Next: C3/D88F
         JMP C3D5DE      ; Queue fade-in

; 0D: Show boat sprite
C3D88F:  LDY $20         ; Delay expired?
         BNE C3D89D      ; Exit if not
         JSR C3D8C6      ; Create boat
         STZ $26         ; Next: Fade-out
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set fade delay
C3D89D:  RTS

; Create boat sprite
C3D8C6:  LDA #$CF        ; Anim ptr HB
         LDY #$F7B9      ; Anim ptr LBs
         LDX #$50F8      ; Pos: 248, 80
         JSR C3F90C      ; Create L-Half
         REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set L-Half's
         SEP #$20        ; 8-bit A
         LDY #C3D91A     ; C3/D91A
         JSR qanim1      ; Queue R-Half
         REP #$20        ; 16-bit A
         LDA #$FFC0      ; H-Spd: -0.25 px
         STA $7E34C9,X   ; Set R-Half's
         SEP #$20        ; 8-bit A
         PEA $50F8       ; Pos: 248, 80
         PEA $F7AD       ; Anim ptr LBs
         LDA #$CF        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3F90X      ; Set R-Half's

; Animate boat's right half
C3D91A:  BNE C3D934      ; If mode 1

; Mode 0: Initialize timers
C3D922:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0040      ; Frames: 64
         STA $3349,X     ; Set show delay
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3D934:  LDY $3349,X     ; Delay expired?
         BNE C3D940      ; Branch if not
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3D940:  JSR C3DF69      ; Delay -1
         SEC             ; Set to requeue
         RTS

; 10: Start skimming airship scene
C3D945:  JSL $D4CED7     ; Init registers
         JSR C3D50E      ; Color math: BG1
         JSR C3E53F      ; Upload GFX, map
         JSR C3D9EC      ; Get sky; init M7
         JSR C3E337      ; Queue gradient
         JSR C3E31A      ; HDMA: Color math
         JSR C3D6C3      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FF6D      ; Mod index: 109
         STY $C3         ; Set matrices'
         LDY #$034C      ; Vertical angle
         STY $C7         ; Set for sea
         LDY #$FD00      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         JSR C3DA78      ; Create birds
         LDY #C3DB41     ; C3/DB41
         JSR qanim2      ; Queue airship
         LDA #$C2        ; Anim ptr HB
         LDY #$8BA1      ; Anim ptr LBs
         JSR anm_st      ; Set airship's
;        LDA #$78        ; X: 120
;        STA $7E33CA,X   ; C3/DB56...
;        LDA #$58        ; Base Y/2: 88
;        STA $7E344A,X   ; C3/DB5B...
         LDA #$C2        ; Anim ptr HB
         LDY #$8BDC      ; Anim ptr LBs
         LDX #$8080      ; Pos: 128, 128
         JSR C3F90C      ; Create shadow
         JSR C3E0F7      ; Load sea colors
         JSR C3E90A      ; Build text OAM
         LDY #C3E7AE     ; C3/E7AE
         JSR qanim2      ; Queue credits
         LDY #$8B26      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue sea anim
         LDY #C3DA1D     ; C3/DA1D
         JSR qanim3      ; Set to pan sky
         JSR C3E224      ; Queue M7 handler
         INC $26         ; Next: Late bird
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set bird's delay
         JMP C3D5DE      ; Queue fade-in

; Load cloudy sky graphics data, exclude sky from Mode 7
C3D9EC:  JSR C3E376      ; Reset M7 vars
         JSR C3E438      ; Load GFX, map
         JSR C3E2F6      ; Set up M7 HDMA
         JSR C3E0E0      ; Make text black
C3D9FB:  LDY #$3049      ; To BG pal 0
         LDX #$9534      ; C2/9534
         JMP C30FF9      ; Load sky colors

; 11: Show swooping bird
C3DA07:  LDY $20         ; Delay expired?
         BNE C3DA2A      ; Exit if not
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         LDY #C3DBF4     ; C3/DBF4
         JMP qanim1      ; Queue bird OAM

; Scroll sky eastward
C3DA1D:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3DA29      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $39         ; BG2 camera -1
C3DA29:  SEC             ; Set to requeue
C3DA2A:  RTS

; Scroll sky westward
C3DA2B:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3DA37      ; Exit if so
         REP #$20        ; 16-bit A
         INC $39         ; BG2 camera +1
C3DA37:  SEC             ; Set to requeue
         RTS

; Create birds for boat scene
C3DA42:  LDX #$F765      ; Source LBs
         LDA #$CF        ; Source HB
         BRA bird6       ; Create birds

; Create oscillating birds around skimming airship
C3DA78:  LDX #$F77D      ; Source LBs
         LDA #$CF        ; Source HB
         BRA bird6       ; Create birds

; Create birds above grassfield
C3DAA9:  LDX #$F795      ; Source LBs
         LDA #$CF        ; Source HB
bird6:   STX $FD         ; Set src LBs
         STA $FF         ; Set src HB
         LDY $00         ; ROM index: 0
.loop    PHY             ; Save ROM index
         LDY #C3DAE3     ; C3/CB68
         JSR qanim2      ; Queue anim fn
         PLY             ; ROM index
         REP #$20        ; 16-bit A
         LDA [$FD],Y     ; Anim table ptr
         INY             ; ROM index +1
         INY             ; ROM index +1
         STA $7E32C9,X   ; Set bird's
         SEP #$20        ; 8-bit A
         LDA [$FD],Y     ; Base X / 2
         INY             ; ROM index +1
         STA $7E34CA,X   ; Set bird's
         LDA [$FD],Y     ; Base Y
         INY             ; ROM index +1
         STA $7E344A,X   ; Set bird's
         LDA $26         ; Current scene
         CMP #$0C        ; Boat scene?
         BNE .skip       ; Branch if not
         JSR C3F9A6      ; Follow BG1: Y
.skip    CPY #$0018      ; Done 6 birds?
         BNE .loop       ; Loop if not
         RTS

; Animate oscillating bird
C3DAE3:  BNE C3DB02      ; If mode 1

; Mode 0: Initialize data
C3DAEB:  INC $3649,X     ; Mode +1
         LDA.L C3DAE3,X  ; X-Mod index
         STA $3349,X     ; Set bird's
         LDA #$CF        ; Bank: CF
         STA $35CA,X     ; Set ptr HB
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3DB02:  JSR C3DB0F      ; Init X position
         INC $3349,X     ; X-Mod index +1
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update bird's back-and-forth motion (range: -8 to +7)
C3DB0F:  LDA $3349,X     ; X-Mod index
         JSR C3EDC6      ; Fract X mod
         PHA             ; Set original
;        STA $E0         ; Set current
;        LDA $E0         ; Shift right?
         BPL C3DB23      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DB23:  STA $E0         ; Save changes
         PLA             ; Shift right?
         BPL C3DB32      ; Branch if so
         JSR C3DBAC      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3DB35      ; Skip a line
C3DB32:  JSR C3DBAC      ; Modifier / 16
C3DB35:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X/2
         STA $33C9,X     ; Init bird's X
         SEP #$20        ; 8-bit A
         RTS

; Animate skimming airship
C3DB41:  BNE C3DB61      ; If mode 1

; Mode 0: Initialize data
C3DB49:  INC $3649,X     ; Mode +1
         STZ $3349,X     ; Anim timer: 0
         LDA #$78        ; X: 120
         STA $33CA,X     ; Set sprite's
         LDA #$20        ; Base Y/2: 32
         STA $354A,X     ; Set sprite's
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3DB61:  JSR C3DB7A      ; Init Y position
         INC $3349,X     ; Anim timer +1
         LDA $3349,X     ; Anim timer
         CMP #$38        ; Within 56-255?
         BCS C3DB75      ; Branch if so
         JSR C3DBB3      ; Create spray
C3DB75:  JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Update airship's up-and-down motion (range: -8 to +7)
C3DB7A:  LDA $3349,X     ; Anim timer
         REP #$20        ; 16-bit A
         JSR C3EDCA      ; Fract Y mod
         PHA             ; Set original
;        STA $E0         ; Set current
;        LDA $E0         ; Shift down?
         BPL C3DB8E      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3DB8E:  STA $E0         ; Save changes
         PLA             ; Shift down?
         BPL C3DB9D      ; Branch if so
         JSR C3DBAC      ; Modifier / 16
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3DBA0      ; Skip a line
C3DB9D:  JSR C3DBAC      ; Modifier / 16
C3DBA0:  LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Init ship's Y
         SEP #$20        ; 8-bit A
         RTS

; Divide sprite's position modifier by 16
C3DBAC:  LDA $E0         ; Y modifier
         LSR A           ; ÷2
         LSR A           ; ÷4
         LSR A           ; ÷8
         LSR A           ; ÷16
         RTS

; Create water spray
C3DBB3:  LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3DBF3      ; Exit if 1-3
         PHB             ; Save DB
         LDA #$C2        ; Anim ptr HB
         LDY #$8CFB      ; Anim ptr LBs
         LDX #$7C7E      ; Pos: 126, 124
         JSR C3D7B8      ; Create sprite
         PLB             ; Restore DB
         LDA #$18        ; Frames: 24
         STA $3349,X     ; Set hide delay
         REP #$20        ; 16-bit A
         LDA #$0100      ; H-Spd: +1 px
         STA $34C9,X     ; Set sprite's
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $3549,X     ; Set sprite's
C3DBF3:  RTS

; Animate swooping bird
C3DBF4:  BNE C3DC23      ; If mode 1

; Mode 0: Initialize sprite
C3DBFC:  INC $3649,X     ; Mode +1
;        STZ $34CA,X     ; Base X HB: 0
;        STZ $354A,X     ; Base Y HB: 0
         LDA #$CF        ; Anim ptr HB
         LDY #$F722      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$10        ; Pos index: 16
         STA $3349,X     ; Set sprite's
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3DC23:  LDA $33CA,X     ; X position
         CMP #$08        ; Under 8?
         BCS C3DC2E      ; Display if not
         CLC             ; Set to dequeue
         RTS

; Fork: Set X position
C3DC2E:  LDA $3349,X     ; Position index
         JSR C3EDC6      ; Fractional X
         ASL A           ; Double it
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $34C9,X     ; Add base X
         STA $33C9,X     ; Set bird's X

; Fork: Set Y position
C3DC5D:  LDA $3349,X     ; Position index
         JSR C3EDCA      ; Fractional Y
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add base Y
         STA $3449,X     ; Set bird's Y
         INC $3349,X     ; Pos index +1
         JMP oamsec      ; Set OAM; requeue

; 14: Start frontview airship scene
C3DC92:  JSL $D4CED7     ; Init registers
         JSR C3D50E      ; Color math: BG1
         JSL C3E4D8      ; Upload GFX, map
         JSR C3D9EC      ; Get sky; init M7
         JSR C3E337      ; Queue gradient
         JSR C3E31A      ; HDMA: Color math
         JSR C3D6C3      ; Load OBJ colors
         LDY #$0028      ; Y: 40
         STY $3B         ; Set BG2 Y-Pos
         LDY #$FFCD      ; Mod index: 205
         STY $C3         ; Set matrices'
         LDY #$030B      ; Vertical angle
         STY $C7         ; Set for field
         LDY #$F000      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         JSR C3E0F7      ; Load BG1 colors
         JSR C3DAA9      ; Create birds
         LDA #$C2        ; Anim ptr HB
         LDY #$8C15      ; Anim ptr LBs
         LDX #$5878      ; Pos: 120, 88
         JSR C3DF60      ; Create airship
         LDY #$8B29      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue field anim
         JSR C3E920      ; Build text OAM
         LDY #C3E7FC     ; C3/E7FC
         JSR qanim2      ; Queue credits
         LDY #C3DA2B     ; C3/DA2B
         JSR qanim3      ; Set to pan sky
         JSR C3E224      ; Queue M7 handler
         INC $26         ; Next: Late flock
         LDY #$04B0      ; Frames: 1200
         STY $20         ; Set flock delay
         JMP C3D5DE      ; Queue fade-in

; 15: Show late bird flock
C3DD1E:  LDY $20         ; Delay expired?
         BNE C3DDB0      ; Exit if not
         LDA #$03        ; C3/C8A6
         STA $26         ; Next: Fade-out
         LDY #$0708      ; Frames: 1800
         STY $20         ; Set fade delay
         LDY #$5000      ; Pos: 0, 80
         JSR C3DD15      ; Create bird 1
         LDY #$4018      ; Pos: 24, 64
         JSR C3DD15      ; Create bird 2
         LDY #$6840      ; Pos: 64, 104
         JSR C3DD15      ; Create bird 3
         LDY #$4810      ; Pos: 16, 72
;        BRA C3DD15      ; Create bird 4

; Create bird from late flock
C3DD15:  PHY             ; Save position
         LDY #C3DD68     ; C3/DD68
         JSR qanim2      ; Queue anim fn
         JMP C3F90Y      ; Set position

; Animate bird from late flock
C3DD68:  CMP #$10        ; Mode 8?
         BEQ C3DDB1      ; Branch if so
         DEC A           ; Mode 0?
         BPL C3DD9D      ; Branch if not

; Mode 0: Initialize data
C3DD7E:  LDA #$CF        ; Anim ptr HB
         LDY #$F6FF      ; Anim ptr LBs
         JSR anm_st      ; Set bird's
         INC $3649,X     ; Mode +1
;        STZ $35C9,X     ; Course: NE
         JSR C3DDC1      ; Define path
         JSR C3127_      ; Set pose timer

; Modes 1-7: Alter course
C3DD9D:  LDY $3349,X     ; Mode expired?
         BNE C3DDA9      ; Branch if not
         JSR C3DDC1      ; Alter path
C3DDA9:  JSR C3DF69      ; Mode timer -1
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
C3DDB0:  RTS

; Mode 8: Delete if set to wrap horizontally
C3DDB1:  JSR C3EE10      ; Scroll & OAM
         LDA $33CA,X     ; Bird's X
         BNE C3DDBF      ; Requeue if > 0
         CLC             ; Set to dequeue
         RTS             ; Exit
C3DDBF:  SEC             ; Set to requeue
         RTS

; Alter course of bird from late flock
C3DDC1:  INC $3649,X     ; Mode +1
         TXY             ; Queue index
         TDC             ; Clear A
         LDA $35C9,X     ; Path index
         INC $35C9,X     ; Orig Index +1
         ASL A           ; Path index x2
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA.L C3DDEC,X  ; H-Speed
         STA $34C9,Y     ; Set bird's
         LDA.L C3DDEE,X  ; V-Speed
         STA $3549,Y     ; Set bird's
         LDA.L C3DDF0,X  ; Path timer
         STA $3349,Y     ; Set bird's
         SEP #$20        ; 8-bit A
         RTS

; Late bird flock's course
C3DDEC:  dw $0020        ; H-Speed: +0.125 px
         dw $0020        ; H-Speed: +0.125 px
         dw $0020        ; H-Speed: +0.125 px
         dw $0010        ; H-Speed: +0.0625 px
         dw $FFE0        ; H-Speed: -0.125 px
         dw $FFC0        ; H-Speed: -0.25 px
         dw $FF80        ; H-Speed: -0.5 px
C3DDEE:  dw $FFF0        ; V-Speed: -0.0625 px
         dw $0000        ; V-Speed: 0
         dw $0020        ; V-Speed: +0.125 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0040        ; V-Speed: +0.25 px
         dw $0080        ; V-Speed: +0.5 px
C3DDF0:  dw $0384        ; Frames: 900
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $003C        ; Frames: 60
         dw $00B4        ; Frames: 180
         dw $00B4        ; Frames: 180

; 18: Start aerial-view plains scene
C3DE24:  JSL $D4CED7     ; Init registers
         JSR C3D50E      ; Color math: BG1
         JSL C3E4D8      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CB8F     ; HDMA: Matrices
         LDY #$1800      ; Base divisor
         STY $C5         ; Set matrices'
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         JSR C3E0E0      ; Make text black
         JSR C3E0F7      ; Load BG1 colors
         LDY #$8AEA      ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         JSR C3E1A9      ; Queue field anim
         JSR C3E936      ; Build text OAM
         LDY #C3E84A     ; C3/E84A
         JSR qanim2      ; Queue credits
         JSR C3E224      ; Queue M7 handler
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Fade-out
         LDY #$0E10      ; Frames: 3600
         STY $20         ; Set fade delay
         JMP C3D5DE      ; Queue fade-in

; 1C: Start rearview airship scene
C3DE6D:  JSL $D4CED7     ; Init registers
         JSL C3E4D8      ; Upload GFX, map
         JSR C3E0C8      ; Upload balloon
         JSR C3D9EC      ; Get sky; init M7
         JSR C3E337      ; Queue gradient
         JSR C3E31A      ; HDMA: Color math
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         LDY #$02DC      ; Vertical angle
         STY $C7         ; Set for field
         JSR C3ED22      ; Make matrix tbl
         JSR C3E2BF      ; Useless...
         LDY #$0010      ; Y: 16
         STY $3B         ; Set BG2 Y-Pos
         JSR C3E0E0      ; Make text black
         JSR C3D6C3      ; Load OBJ colors
         JSR C3E0F7      ; Load BG1 colors
         JSR C3E941      ; Build text OAM
         LDY #C3E898     ; C3/E898
         JSR qanim2      ; Queue credits
         LDY #C3DF1E     ; C3/DF1E
         JSR qanim0      ; Queue BG scroll
         LDX #$1444      ; Pos: 68, 20
         JSR C3DF36      ; Create SW rotor
         LDX #$14AC      ; Pos: 172, 20
         JSR C3DF4B      ; Create SE rotor
         LDX #$E860      ; Pos: 96, 232
         JSR C3DF36      ; Create NW rotor
         LDX #$E890      ; Pos: 144, 232
         JSR C3DF4B      ; Create NE rotor
         LDA #$C2        ; Anim ptr HB
         LDY #$8C50      ; Anim ptr LBs
         LDX #$F848      ; Pos: 72, 248
         JSR C3DF60      ; Create airship
         LDA #$03        ; C3/D81B
         STA $26         ; Next: Fade-out
         LDY #$08AC      ; Frames: 2220
         STY $20         ; Set fade delay
         JMP C3D5DE      ; Queue fade-in

; Scroll field and sky for rearview airship scene
C3DF1E:  LDA $23         ; NMI count
         AND #$7F        ; 0 or 128?
         BNE C3DF26      ; Branch if not
         INC $3B         ; Shift sky up
C3DF26:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         BCS C3DF34      ; Exit if so
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; Move field down
C3DF34:  SEC             ; Set to requeue
         RTS

; Create NW or SW airship rotor
C3DF36:  LDA #$C2        ; Anim ptr HB
         LDY #$8D2E      ; Anim ptr LBs
         BRA C3DF60      ; Branch below

; Create NE or SE airship rotor
C3DF4B:  LDA #$C2        ; Anim ptr HB
         LDY #$8D81      ; Anim ptr LBs

; Create frontview or rearview airship or rotor
C3DF60:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3DF7C     ; C3/DF7C
         JSR qanim2      ; Queue OAM fn
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         PLA             ; X position
         STA $7E33CA,X   ; Set rotor's
         PLA             ; Y position
         STA $7E354A,X   ; Set rotor's
         RTS

; Decrease sprite's animation mode timer
C3DF69:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         RTS

; Animate frontview or rearview airship or rotor
C3DF7C:  BNE C3DF8F      ; If mode 1

; Mode 0: Initialize timers
C3DF84:  JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1
         STZ $3349,X     ; Anim timer: 0

; Mode 1: Sustain sprite
C3DF8F:  JSR C3DB7A      ; Set altitute
         INC $3349,X     ; Anim timer +1
oamsec:  JSR C3128C      ; Define OAM
         SEC             ; Set to requeue
         RTS

; Load colors for blue sky and non-sprite airships
C3DF9C:  LDY #$3049      ; To BG pal 0
         LDX #$9594      ; C2/9594
         JSR C30FF9      ; Load fill color
         LDY #$3069      ; To BG pal 1
         LDX #$9594      ; C2/9594
         JMP C30FF9      ; Load the rest

; 20: Start final airship scene
C3DFB3:  JSL $D4CED7     ; Init registers
         JSR C3D50E      ; Color math: BG1
         LDA #$80        ; Map wraps: No
         STA $211A       ; Set M7 settings
         JSR C3E56F      ; Upload GFX, map
         JSR C3E376      ; Reset M7 vars
         JSL $D4CE55     ; HDMA: MS desig
;        LDY #$31C9      ; To OBJ pal 4
;        LDX #$974C      ; C2/974C
;        JSR C30FF9      ; No text...
;        LDY #$31E9      ; To OBJ pal 5
;        LDX #$9744      ; C2/9744
;        JSR C30FF9      ; No text...
;        JSR C3E0F7      ; No field...
         JSR C3DF9C      ; Load BG colors
         LDY #$0001      ; Zoom-out: 1
         STY $BB         ; Set matrix A
         STY $C1         ; Set matrix D
         LDY #$0008      ; X: 8
         STY $B7         ; Set center X
         LDY #$0018      ; Y: 24
         STY $B9         ; Set center Y
         LDY #$FFD8      ; X: -40
         STY $35         ; Set BG1 X-Pos
         LDY #$FFD0      ; Y: -48
         STY $37         ; Set BG1 Y-Pos
         LDY #C3E0A6     ; C3/E0A6
         JSR qanim0      ; Queue zoom-out
         INC $26         ; Next: C3/E01A
         LDY #$0096      ; Frames: 150
         STY $20         ; Set fade delay
         LDY #C3E02C     ; C3/E02C
         JSR qanim0      ; Queue rotor fn
         JMP C3D5DE      ; Queue fade-in

; 21: Fade final airship
C3E01A:  LDY $20         ; Delay expired?
         BNE C3E053      ; Exit if not
         STZ $26         ; Next: Fade-out
         LDA #$78        ; Frames: 120
         STA $20         ; Set fade timer
         JSR C3F0A5      ; Fade BG pal 1+2
         JMP C3F17B      ; Fade BG pal 0

; Animate final airship's rotors
C3E02C:  REP #$20        ; 16-bit A
         LDA $23         ; NMI count
         LSR A           ; Odd value?
         LDA #$4F51      ; Tiles: 79, 81
         BCS C3E043      ; If odd count
         LDA #$5A59      ; Tiles: 90, 89
C3E043:  STA $9849       ; Set rotor tiles
         SEP #$20        ; 8-bit A

; Fork: Set to refresh rotors
C3E054:  LDY #$0283      ; L-Rotor adr
         STY $14         ; Set VRAM ptr1
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src1 LBs
         LDY #$0206      ; R-Rotor adr
         STY $1B         ; Set VRAM ptr2
         LDY #$984A      ; 7E/984A
         STY $1D         ; Set src2 LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src1 HB
         STA $1F         ; Set src2 HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set src1 size
         STY $19         ; Set src2 size
         SEC             ; Set to requeue
C3E053:  RTS

; Animate sideview airship's rotors
C3E076:  LDA $23         ; NMI count
         LSR A           ; Odd value?
         LDA #$58        ; Tile: 88
         BCS C3D105      ; If odd count
         LDA #$34        ; Tile: 52
C3D105:  STA $9849       ; Set rotors'

; Fork: Set to refresh rotors
C3E092:  LDY #$0892      ; $0892
         STY $14         ; Set VRAM ptr
         LDY #$9849      ; 7E/9849
         STY $16         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src HB
         LDY #$0001      ; Bytes: 1
         STY $12         ; Set data size
         SEC             ; Set to requeue
         RTS

; Process queued zoom-out for final airship scene
C3E0A6:  LDA $23         ; NMI count
         AND #$07        ; Now 0-7
         REP #$20        ; 16-bit A
         BNE C3E0BB      ; Branch if > 0
         INC $B7         ; M7 center X +1
         INC $B9         ; M7 center Y +1
C3E0BB:  INC $BB         ; Matrix A +1
         INC $BB         ; Matrix A +1
         INC $C1         ; Matrix D +1
         INC $C1         ; Matrix D +1
         SEC             ; Set to requeue
         RTS

; Upload rearview airship's balloon graphics
C3E0C8:  LDY #$D7BA      ; 7E/D7BA
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0580      ; Bytes: 1408
         LDY #$6C00      ; VRAM pointer
         JMP C3ED0_      ; Upload data

; Initialize credits' colors to black for fade-in
C3E0E0:  LDY #$31C9      ; To OBJ pal 4
         JSR black       ; Do big font
         LDY #$31E9      ; To OBJ pal 5
         JMP black       ; Do small font

; Load BG1 palettes for credits scenes
C3E0F7: ;LDY #$3069      ; To BG pal 1
;        LDX #$95B4      ; C2/95B4
;        JSR C30FF9      ; C3/DFAF...
         LDY #$3089      ; To BG pal 2
         LDX #$95D4      ; C2/95D4
         JSR C30FF9      ; Do sea
         LDY #$30A9      ; To BG pal 3
         LDX #$95F4      ; C2/95F4
         JSR C30FF9      ; Do clouds
         LDY #$30C9      ; To BG pal 4
         LDX #$9614      ; C2/9614
         JSR C30FF9      ; Do trees
         LDY #$3109      ; To BG pal 6
         LDX #$9634      ; C2/9634
         JSR C30FF9      ; Do lake
         LDY #$3129      ; To BG pal 7
         LDX #$9654      ; C2/9654
         JMP C30FF9      ; Do grass

; Scroll actor's pseudonym down
C3E13A:  LDY $CF         ; Scroll timer
         CPY $64         ; At endpoint?
         BEQ C3E14E      ; Dequeue if so
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3E14C      ; Exit if 1-3
         REP #$20        ; 16-bit A
         DEC $3F         ; BG3 camera up
C3E14C:  SEC             ; Set to requeue
         RTS             ; Exit
C3E14E:  CLC             ; Set to dequeue
         RTS

; Process queued field fade-in
C3E150:  BNE C3E167      ; If mode 1

; Mode 0: Initialize brightness
C3E158:  INC $3649,X     ; Mode +1
         LDA #$01        ; BRT: 1 and ON
         STA $344A,X     ; Set next BRT
         LDA #$0F        ; Frames: 15
         STA $3349,X     ; Set timer

; Mode 1: Increase brightness
C3E167:  LDA $3349,X     ; Timer expired?
         BEQ C3E17B      ; Finalize if so
         LDA $344A,X     ; Next brightness
         STA $44         ; Set as current
         INC $344A,X     ; Next BRT +1
         DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3E17B:  LDA #$0F        ; BRT: 15 and ON
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Process queued field fade-out
C3E181:  BNE C3E193      ; If mode 1

; Mode 0: Initialize brightness
C3E189:  INC $3649,X     ; Mode +1
         LDA #$0F        ; BRT: 15 and ON
         STA $33CA,X     ; Set next BRT

; Mode 1: Decrease brightness
C3E193:  LDY $20         ; Timer expired?
         BEQ C3E1A3      ; Finalize if so
         LDA $33CA,X     ; Next brightness
         STA $44         ; Set as current
         DEC $33CA,X     ; Next BRT -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3E1A3:  LDA #$80        ; BRT: 0 and OFF
         STA $44         ; Set brightness
         CLC             ; Set to dequeue
         RTS

; Queue Mode 7 animation script loading
C3E1A9:  PHA             ; Save ptr HB
         PHY             ; Save ptr LBs
         LDY #C3E1C3     ; C3/E1C3
         JSR qanim1      ; Queue anim fn
         PLY             ; Anim ptr LBs
         PLA             ; Anim ptr HB
         JMP anm_st      ; Put in queue

; Load parameters for Mode 7 animation
C3E1C3:  BNE C3E1D3      ; If mode 1

; Mode 0: Initialize sequence timer
C3E1CB:  JSR C31271      ; Set anim timer
         INC $3649,X     ; Mode +1

; Mode 1: Load animation flags
C3E1D3:  JSR C31292      ; Anim timer -1
         TDC             ; Clear A
         LDA $36C9,X     ; Anim index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Anim flags
         STA $04         ; Set as current
         SEC             ; Set to requeue
         RTS

; Refresh Mode 7 registers (NMI)
C3E1E7:  LDA $BB         ; Matrix A LB
         STA $211B       ; To register
         LDA $BC         ; Matrix A HB
         STA $211B       ; To register
         LDA $BD         ; Matrix B LB
         STA $211C       ; To register
         LDA $BE         ; Matrix B HB
         STA $211C       ; To register
         LDA $BF         ; Matrix C LB
         STA $211D       ; To register
         LDA $C0         ; Matrix C HB
         STA $211D       ; To register
         LDA $C1         ; Matrix D LB
         STA $211E       ; To register
         LDA $C2         ; Matrix D HB
         STA $211E       ; To register
         LDA $B7         ; Center X LB
         STA $211F       ; To register
         LDA $B8         ; Center X HB
         STA $211F       ; To register
         LDA $B9         ; Center Y LB
         STA $2120       ; To register
         LDA $BA         ; Center Y HB
         STA $2120       ; To register
         RTS

; Queue Mode 7 animation script decoding
C3E224:  LDY #C3E22D     ; C3/E22D
         JMP qanim0      ; Queue anim fn

; Decode parameters for Mode 7 animation
C3E22D:  LDA $04         ; Anim flags
         BIT #$10        ; Tilt right?
         BEQ C3E23B      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C3         ; Mod index +1
         SEP #$20        ; 8-bit A
;        INC $59         ; No use...

; Fork: Rotate counterclockwise
C3E23B:  LDA $04         ; Anim flags
         BIT #$20        ; Tilt left?
         BEQ C3E249      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C3         ; Mod index -1
         SEP #$20        ; 8-bit A
;        DEC $59         ; No use...

; Fork: Rotate forward
C3E249:  LDA $04         ; Anim flags
         ASL A           ; Tilt up?
         BPL C3E255      ; Skip if not
         REP #$20        ; 16-bit A
         INC $C7         ; Matrix mod +1
         SEP #$20        ; 8-bit A

; Fork: Rotate backward
C3E255:  LDA $05         ; Anim flags
         ASL A           ; Tilt down?
         BPL C3E261      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $C7         ; Matrix mod -1
         SEP #$20        ; 8-bit A

; Fork: Zoom in
C3E261:  LDA $04         ; Anim flags
;        BIT #$80        ; Inc divisor?
         BPL C3E269      ; Skip if not
         INC $C6         ; Divisor +1

; Fork: Zoom out
C3E269:  LDA $05         ; Anim flags
;        BIT #$80        ; Dec divisor?
         BPL C3E271      ; Skip if not
         DEC $C6         ; Divisor -1

; Fork: Scroll southward
C3E271:  LDA $05         ; Anim flags
         BIT #$08        ; Scroll down?
         BEQ C3E27F      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B9         ; Center Y -1
         DEC $37         ; BG1 Y-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll northward
C3E27F:  LDA $05         ; Anim flags
         BIT #$04        ; Scroll up?
         BEQ C3E28D      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B9         ; Center Y +1
         INC $37         ; BG1 Y-Pos +1
         SEP #$20        ; 8-bit A

; Fork: Scroll eastward
C3E28D:  LDA $05         ; Anim flags
         BIT #$02        ; Scroll right?
         BEQ C3E29B      ; Skip if not
         REP #$20        ; 16-bit A
         DEC $B7         ; Center X -1
         DEC $35         ; BG1 X-Pos -1
         SEP #$20        ; 8-bit A

; Fork: Scroll westward
C3E29B:  LDA $05         ; Anim flags
         LSR A           ; Scroll left?
         BCC C3E2A9      ; Skip if not
         REP #$20        ; 16-bit A
         INC $B7         ; Center X +1
         INC $35         ; BG1 X-Pos +1

; Fork: Build Mode 7 matrix tables
C3E2A9:  JSR C3E2E3      ; Cap center X/Y
         LDA $04         ; Anim flags
         AND #$F0FF      ; Only scrolling?
         SEP #$20        ; 8-bit A
         BEQ C3E2BD      ; Exit if so
         JSR C3ED22      ; Build tables
         JSR C3E2BF      ; Useless...
C3E2BD:  SEC             ; Set to requeue
         RTS

; Copy matrix data for first scanline to global variables (useless)
C3E2BF:  LDY $07C2       ; Mtx A overscan
         STY $07C4       ; Never read...
         LDY $0984       ; Mtx B overscan
         STY $0986       ; Never read...
         LDY $0B46       ; Mtx C overscan
         STY $0B48       ; Never read...
         LDY $0602       ; Mtx A, line 1
         STY $BB         ; Set global A
         STY $C1         ; Set global D
         LDY $07C4       ; Mtx B, line 1
         STY $BD         ; Set global B
         LDY $0986       ; Mtx C, line 1
         STY $BF         ; Set global C
         RTS

; Keep Mode 7 center X and Y within boundaries
C3E2E3:  REP #$20        ; 16-bit A
         LDA #$E000      ; Bits to discard
         TRB $B7         ; Cap center X
         TRB $B9         ; Cap center Y
         RTS

; Configure Mode 7 not to apply to cloudy sky
C3E2F6:  JSL $D4CB8F     ; HDMA: Matrices
         STZ $4310       ; 1Rx1B to PPU
         LDA #$05        ; $2105
         STA $4311       ; To BG mode
         LDY #C3E315     ; C3/E315
         STY $4312       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4314       ; Set src HB
         LDA #$02        ; Channel: 1
         TSB $43         ; Queue HDMA-1
         RTS

; BG mode and tile size per scanline
C3E315:  db $47,$01      ; Mode 1, 8x8 tiles
         db $01,$07      ; Mode 7
         db $00          ; End

; Set color addition and math for field and for cloudy sky
C3E31A:  LDA #$01        ; 2Rx1B to PPU
         STA $4330       ; Set DMA mode
         LDA #$30        ; $2130, $2131
         STA $4331       ; To color regs
         LDY #C3E352     ; C3/E352
         STY $4332       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4334       ; Set src HB
         LDA #$08        ; Channel: 3
         TSB $43         ; Queue HDMA-3
         RTS

; Queue gradient effect for field under sky
C3E337:  STZ $4320       ; 1Rx1B to PPU
         LDA #$32        ; $2132
         STA $4321       ; To fixed color
         LDY #C3E359     ; C3/E359
         STY $4322       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4324       ; Set src HB
         LDA #$04        ; Channel: 2
         TSB $43         ; Queue HDMA-2
         RTS

; Color addition and math per scanline
C3E352:  db $47,$80,$41  ; BG1, inside window, half mode
         db $01,$82,$01  ; BG1, inside window, add subscreen
         db $00          ; End

; Gradient table for the above
C3E359:  db $47,$E0      ; RGB: 0
         db $01,$ED      ; RGB: 13
         db $01,$EB      ; RGB: 11
         db $01,$EA      ; RGB: 10
         db $02,$E9      ; RGB: 9
         db $03,$E8      ; RGB: 8
         db $04,$E7      ; RGB: 7
         db $05,$E6      ; RGB: 6
         db $06,$E5      ; RGB: 5
         db $07,$E4      ; RGB: 4
         db $08,$E3      ; RGB: 3
         db $0C,$E2      ; RGB: 2
         db $0F,$E1      ; RGB: 1
         db $1E,$E0      ; RGB: 0
         db $00          ; End

; Reset Mode 7 parameters
C3E376:  LDY #$0100      ; 256
         STY $B7         ; Set center X
         LDY #$0080      ; 128
         STY $B9         ; Set center Y
         STY $35         ; Set BG1 X-Pos
;        STZ $58         ; No use...
;        LDA #$40        ; No use...
;        STA $59         ; No use...
         TDC             ; Clear A
         TAY             ; Clear Y
         STY $37         ; BG1 Y-Pos: 0
;        LDY $00         ; Vertical angle
         STY $C7         ; Set for BG1
;        LDY $00         ; Mod index: 0
         STY $C3         ; Set matrices'
         LDY #$0100      ; Base divisor
         STY $C5         ; Set matrices'
         RTS

; Unpack and upload graphics and tilemaps for sideview airship scene
C3E39C:  JSR C3E3C9      ; Upload font GFX
         JSR C3E616      ; Unpack map, GFX
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E3BA      ; Insert tilemap A
         JSR C3E599      ; Upload M7 map A
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E3BA      ; Insert tilemap B
         JMP C3E5B1      ; Upload M7 map B

; Assemble half of tilemap for sideview airship scene
C3E3BA:  JSR C3E5F2      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc LBs
         LDA #$7E        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Unpack and upload font graphics for credits
C3E3C9:  LDY #$B500      ; Source LBs
         LDA #$CE        ; Source HB
         JSR C3ECB1      ; Load big font
         JSR C3E3FC      ; Set as 16x16
         JSR C3E47D      ; Src: 7E/C000
         LDX #$0C00      ; Bytes: 3072
         LDY #$7000      ; VRAM pointer
         JSR C3ECD6      ; Upload font
         LDY #$81C0      ; C4/81C0
         STY $E7         ; Set src LBs
         LDA #$C4        ; Src HB: C4
         LDX #$0200      ; Bytes: 512
         LDY #$7E00      ; VRAM pointer
         JMP C3ECD6      ; Do small font

; Expand large font graphics to 16x16 for credits
C3E3FC:  PHB             ; Save DB
         JSR db7e        ; Set DB to 7E
;        TDC             ; Clear A
         TAX             ; ROM index: 0
         TXY             ; Dst index: 0
C3E404:  PHX             ; Save ROM index
         TDC             ; Clear A
         LDA $C2984C,X   ; Tile index
         REP #$20        ; 16-bit A
         JSR x16         ; x16
         TAX             ; Index it
         SEP #$20        ; 8-bit A
         LDA #$10        ; Rows: 8
C3E417:  PHA             ; Save counter
         LDA $C000,X     ; 8 px, 1 plane
         STA $C400,Y     ; Put in buffer
         INX             ; Src index +1
         INY             ; Dst index +1
         PLA             ; Counter
         DEC A           ; Counter -1
         BNE C3E417      ; Loop till zero

; Fork: Blank right-hand 8x8 tile
C3E423:  TDC             ; Clear A
         TAX             ; Counter: 0
C3E425:  STA $C400,Y     ; Clear a plane
         INY             ; Dst index +1
         INX             ; Counter +1
         CPX #$0010      ; Done 8 rows?
         BNE C3E425      ; Loop if not
         PLX             ; ROM index
         INX             ; ROM index +1
         CPX #$0040      ; Done 64 tiles?
         BNE C3E404      ; Loop if not
         PLB             ; Restore DB
         RTS

; Unpack and upload cloudy sky graphics and tilemap
C3E438:  REP #$20        ; 16-bit A
         LDA $EEB206     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB208     ; Source HB
         JSR C3ECB1      ; Unpack graphics
         JSR C3E47D      ; Src: 7E/C000
         LDX #$1A20      ; Bytes: 6688
         LDY #$4000      ; VRAM pointer
         JSR C3ED0_      ; Upload graphics
         REP #$20        ; 16-bit A
         LDA $EEB209     ; Source LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         LDA $EEB20B     ; Source HB
         JSR C3ECB1      ; Unpack tilemap
         LDY #$2000      ; Add: Priority
         STY $ED         ; Set complement
         JSR C3E47D      ; Src: 7E/C000
         LDX #$0400      ; Bytes: 1024
         LDY #$5000      ; VRAM pointer
         JMP C3ED09      ; Upload tilemap

; Set source for uploading decompressed data
C3E47D:  LDY #$C000      ; 7E/C000
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         RTS

; Unpack and upload graphics and tilemaps for dense clouds
C3E487:  JSR C3E3C9      ; Upload font GFX
         JSR C3E616      ; Unpack map, GFX
         JSR C3E63B      ; Upload sprites
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E4A8      ; Insert tilemap A
         JSR C3E599      ; Upload M7 map A
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E4A8      ; Insert tilemap B
         JMP C3E5B1      ; Upload M7 map B

; Assemble half of tilemap for dense clouds
C3E4A8:  JSR C3E5EB      ; Set ptrs loc
         LDX #$FC1A      ; Tiles loc LBs
         LDA #$7E        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Add 4bpp graphics to Mode 7 map (first 128 tiles)
C3E4B7:  LDY $00         ; Palette index
         LDX #$9800      ; Src: 7F/9800
         JMP C3E6B4      ; Convert GFX

; Add 4bpp graphics to Mode 7 map (last 128 tiles)
C3E4C7:  LDY #$0080      ; Palette index
         LDX #$A800      ; Src: 7F/A800
         JMP C3E6B4      ; Convert GFX

; Unpack and upload graphics and tilemaps for grassfield scenes
C3E4D8:  JSR C3E3C9      ; Upload font GFX
         JSR C3E5F9      ; Unpack map, GFX
         JSR C3E63B      ; Upload sprites
         BRA C3E4E7      ; Upload M7 map

; Unpack and upload graphics and tilemaps for second-last airship scene
C3E4E4:  JSR C3E5F9      ; Unpack map, GFX
C3E4E7:  JSR C3E5C9      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E500      ; Insert tilemap A
         JSR C3E599      ; Upload M7 map A
         JSR C3E5C9      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E500      ; Insert tilemap B
         JSR C3E5B1      ; Upload M7 map B
         RTL

; Assemble half of grassfield tilemap
C3E500:  JSR C3E5DA      ; Set ptrs loc
         LDX #$DD3A      ; Tiles loc
         LDA #$7E        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Unpack and upload graphics and tilemaps for boat scene
C3E50F:  JSR C3E3C9      ; Upload font GFX
         JSR C3E5F9      ; Unpack map, GFX
         JSR C3E63B      ; Upload sprites
         JSR C3E5C9      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E530      ; Insert tilemap A
         JSR C3E599      ; Upload M7 map A
         JSR C3E5C9      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E530      ; Insert tilemap B
         BRA C3E5B1      ; Upload M7 map B

; Assemble half of tilemap for sea with boat
C3E530:  JSR C3E5E4      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc LBs
         LDA #$7F        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Unpack and upload graphics and tilemaps for skimming airship scene
C3E53F:  JSR C3E3C9      ; Upload font GFX
         JSR C3E5F9      ; Unpack map, GFX
         JSR C3E63B      ; Upload sprites
         JSR C3E5C9      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E560      ; Insert tilemap A
         JSR C3E599      ; Upload M7 map A
         JSR C3E5C9      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E560      ; Insert tilemap B
         BRA C3E5B1      ; Upload M7 map B

; Assemble half of tilemap for sea without boat
C3E560:  JSR C3E5EB      ; Set ptrs loc
         LDX #$2CFA      ; Tiles loc
         LDA #$7F        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Unpack and upload graphics and tilemaps for final airship scene
C3E56F:  JSR C3E616      ; Unpack map, GFX
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4B7      ; Convert M7 GFX A
         JSR C3E58A      ; Insert tilemap
         JSR C3E599      ; Upload M7 map A
         JSR C3E5D0      ; Pal numbers loc
         JSR C3E4C7      ; Convert M7 GFX B
         JSR C3E58A      ; Insert tilemap B
         BRA C3E5B1      ; Upload M7 map B

; Assemble half of tilemap for final airship scene
C3E58A:  JSR C3E5DA      ; Set ptrs loc
         LDX #$041A      ; Tiles loc
         LDA #$7F        ; Tiles loc HB
         JMP C3E66B      ; Build map

; Upload upper half of Mode 7 map
C3E599:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$4000      ; Bytes: 16384
         LDY $00         ; VRAM pointer
         JMP C3ED0_      ; Upload map

; Upload lower half of Mode 7 map
C3E5B1:  LDY #$B800      ; 7F/B800
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$4000      ; Bytes: 16384
         LDY #$2000      ; VRAM pointer
         JMP C3ED0_      ; Upload map

; Set palette index table location for plains or sea
C3E5C9:  LDX #$F991      ; Ptrs loc LBs
         LDA #$CF        ; Ptrs loc HB
         BRA C3E5D5      ; Set pointer

; Set palette index table location for sky scenes
C3E5D0:  LDX #$F919      ; CF/F919
         LDA #$CF        ; Bank: CF
C3E5D5:  STX $91         ; Set loc LBs
         STA $93         ; Set loc HB
         RTS

; Set tilemap pointer table location for final scenes
C3E5DA:  LDX #$FA99      ; CF/FA99
         LDA #$CF        ; Bank: CF
C3E5DF:  STX $F7         ; Set loc LBs
         STA $F9         ; Set loc HB
         RTS

; Set tilemap pointer table location for boat scene
C3E5E4:  LDX #$FA79      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3E5DF      ; Set pointer

; Set tilemap pointer table location for skimming airship and cloud scenes
C3E5EB:  LDX #$FA59      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3E5DF      ; Set pointer

; Set tilemap pointer table location for sideview airship scene
C3E5F2:  LDX #$FAB9      ; Table loc LBs
         LDA #$CF        ; Table loc HB
         BRA C3E5DF      ; Set pointer

; Unpack credits scene GFX and maps, move ocean and grassfield GFX
C3E5F9:  JSR C3E633      ; Unpack data
         LDX #$141A      ; 7F/141A
         STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
;        LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$18E0      ; Bytes: 6368
         BRA C3E653      ; Move data

; Unpack credits scene GFX and tilemaps, move cloud and BG airship GFX
C3E616:  JSR C3E633      ; Unpack data
         LDX #$ED3A      ; 7E/ED3A
         STX $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDY #$9800      ; 7F/9800
         STY $EB         ; Set dst LBs
         LDA #$7F        ; Bank: 7F
         STA $ED         ; Set dst HB
         LDY #$0EE0      ; Bytes: 3808
         BRA C3E653      ; Move data

; Unpack non-font graphics for credits scenes
C3E633:  LDY #$568F      ; Source LBs
         LDA #$D9        ; Source HB
         JMP C3ECB1      ; Unpack data

; Upload non-font sprite graphics for credits scenes
C3E63B:  JSR C3E47D      ; Src: 7E/C000
         LDX #$17BA      ; Bytes: 6074
         LDY #$6000      ; VRAM pointer
         JMP C3ED0_      ; Upload data

; Relocate decompressed data, adjust attributes if tilemap
C3E653:  STY $EF         ; Set data size
;        STZ $F1         ; ...
;        STZ $F2         ; ...
         REP #$20        ; 16-bit A
         LDY $00         ; Index: 0
C3E65B:  LDA [$E7],Y     ; Unpacked data
;        CLC             ; ...
;        ADC $F1         ; ...
         STA [$EB],Y     ; Put in buffer
         INY             ; Index +1
         INY             ; Index +1
         CPY $EF         ; Past range?
         BNE C3E65B      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Add a 128x64 tilemap to Mode 7 map
C3E66B:  STX $F1         ; Set src LBs
         STA $F3         ; Set src HB
         LDY $00         ; Index: 0
C3E66D:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Src index
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Dst index
         STA $E7         ; Memorize it
         INY             ; Index +1
         INY             ; Index +1
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Src index
         JSR C3E688      ; Copy 32x32 map
         PLY             ; Restore index
         CPY #$0020      ; Done 8 maps?
         BNE C3E66D      ; Loop if not
         RTS

; Add a 32x32 tilemap to Mode 7 map
C3E688:  LDA #$20        ; Rows: 32
         STA $E0         ; Set counter
C3E691:  LDA #$20        ; Columns: 32
         STA $E1         ; Set counter
         LDX $E7         ; Dst index
C3E697:  LDA [$F1],Y     ; Tile number
         STA $7FB800,X   ; Add to M7 map
         INY             ; Src index +1
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEC $E1         ; One less column
         BNE C3E697      ; Loop till last
         INC $E8         ; Dst: +128 tiles
         DEC $E0         ; One less row
         BNE C3E691      ; Loop till last
         RTS

; Add 4bpp tile graphics to Mode 7 map
C3E6B4:  LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STX $E7         ; Set src LBs
         STY $E4         ; Set pal index
         LDA #$80        ; Tiles: 128
         STA $ED         ; Set counter
         LDX $00         ; Dst index: 0
C3E6BF:  LDA #$08        ; Rows left: 8
         STA $E6         ; Set counter

; Fork: Load 8-pixel row
C3E6C3:  REP #$20        ; 16-bit A
         LDY #$0010      ; Src index: 16
         LDA [$E7]       ; Planes A & B
         STA $F1         ; Memorize them
         LDA [$E7],Y     ; Planes C & D
         STA $EF         ; Memorize them
         SEP #$20        ; 8-bit A

; Fork: Convert each pixel in row
C3E6D3:  LDY #$0008      ; Pixels: 8
C3E6D6:  TDC             ; Clear A
         ASL $F0         ; Get plane D
         ROL A           ; Roll into A
         ASL $EF         ; Get plane C
         ROL A           ; Roll into A
         ASL $F2         ; Get plane B
         ROL A           ; Roll into A
         ASL $F1         ; Get plane A
         ROL A           ; Roll into A
         AND #$0F        ; Blank pixel?
         BEQ C3E6F7      ; Branch if so
         STA $E0         ; Save 0-15 color
         PHY             ; Save pixels left
         LDY $E4         ; Palette index
         LDA [$91],Y     ; Palette number
         PLY             ; Pixels left
         JSR x16         ; Palette x 16
         ORA $E0         ; Add 0-15 color
C3E6F7:  STA $7FB801,X   ; Set map pixel
         INX             ; Dst index +1
         INX             ; Dst index +1
         DEY             ; One less pixel
         BNE C3E6D6      ; Loop till last

; Fork: Do tile's next row
C3E6FF:  LDY $E7         ; Source
         INY             ; Source +1
         INY             ; Source +1
         STY $E7         ; Save changes
         DEC $E6         ; One less row
         BNE C3E6C3      ; Loop till last

; Fork: Do next tile
C3E709:  REP #$21        ; 16-bit A; C-
         INC $E4         ; Pal index +1
         LDA $E7         ; Source
         ADC #$0010      ; Skip done data
         STA $E7         ; Save changes
         TDC             ; Clear A
         SEP #$20        ; 8-bit A
         DEC $ED         ; One less tile
         BNE C3E6BF      ; Loop till last
         RTS

; Handle credits timing for sideview airship scene
C3E71E:  LDY $CF         ; Scene timer
         CPY #$003C      ; 60?
         BNE C3E77B      ; Exit if not
         LDX #$988C      ; Source LBs
         JMP credx3      ; Init producer

; Handle credits timing for aerial-view airship scene
C3E730:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3E741      ; Branch if not
         LDX #$9898      ; Source LBs
         JMP credx5      ; Init director

; Fork: Main programmer
C3E741:  CPY #$01AE      ; 430?
         BNE C3E74B      ; Branch if not
         LDX #$98AC      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Graphic director (page 1)
C3E74B:  CPY #$0352      ; 850?
         BNE C3E755      ; Branch if not
         LDX #$98C4      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Graphic director (page 2)
C3E755:  CPY #$04F6      ; 1270?
         BNE C3E75F      ; Branch if not
         LDX #$98DC      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Music
C3E75F:  CPY #$069A      ; 1690?
         BNE C3E769      ; Branch if not
         LDX #$98F4      ; Source LBs
         JMP credx3      ; Init sprites

; Fork: Image design
C3E769:  CPY #$083E      ; 2110?
         BNE C3E773      ; Branch if not
         LDX #$9900      ; Source LBs
         JMP credx4      ; Init sprites

; Fork: Battle planner
C3E773:  CPY #$09E2      ; 2530?
         BNE C3E77B      ; Exit if not
         LDX #$9910      ; Source LBs
         JMP credx6      ; Init sprites
C3E77B:  SEC             ; Set to requeue
         RTS

; Handle credits timing for boat scene
C3E77E:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3E78F      ; Branch if not
         LDX #$9928      ; Source LBs
         JMP credx8      ; Init field pln

; Fork: Event planner
C3E78F:  CPY #$01AE      ; 430?
         BNE C3E799      ; Branch if not
         LDX #$9948      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Effect programmer
C3E799:  CPY #$0352      ; 850?
         BNE C3E7A3      ; Branch if not
         LDX #$9960      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Battle programmer
C3E7A3:  CPY #$04F6      ; 1270?
         BNE C3E77B      ; Exit if not
         LDX #$9978      ; Source LBs
         JMP credx4      ; Init sprites

; Handle credits timing for skimming airship scene
C3E7AE:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3E7BF      ; Branch if not
         LDX #$9988      ; Source LBs
         JMP credx4      ; Init sound prg

; Fork: Effect graphic designer
C3E7BF:  CPY #$01AE      ; 430?
         BNE C3E7C9      ; Branch if not
         LDX #$9998      ; Source LBs
         JMP credx5      ; Init sprites

; Fork: Field graphic designer (page 1)
C3E7C9:  CPY #$0352      ; 850?
         BNE C3E7D3      ; Branch if not
         LDX #$99AC      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Field graphic designer (page 2)
C3E7D3:  CPY #$04F6      ; 1270?
         BNE C3E7DD      ; Branch if not
         LDX #$99D0      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Field graphic designer (page 3)
C3E7DD:  CPY #$069A      ; 1690?
         BNE C3E7E7      ; Branch if not
         LDX #$99F4      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Monster graphic designer
C3E7E7:  CPY #$083E      ; 2110?
         BNE C3E7F1      ; Branch if not
         LDX #$9A18      ; Source LBs
         JMP credx5      ; Init sprites

; Fork: Object graphic designer
C3E7F1:  CPY #$09E2      ; 2530?
         BNE C3E847      ; Exit if not
         LDX #$9A2C      ; Source LBs
         JMP credx5      ; Init sprites

; Handle credits timing for frontview airship scene
C3E7FC:  LDY $CF         ; Scene timer
         CPY #$000A      ; 10?
         BNE C3E80D      ; Branch if not
         LDX #$9A40      ; Source LBs
         JMP credx4      ; Init sound eng

; Fork: Sound effect (page 1)
C3E80D:  CPY #$01AE      ; 430?
         BNE C3E817      ; Branch if not
         LDX #$9A50      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Sound effect (page 2)
C3E817:  CPY #$0352      ; 850?
         BNE C3E821      ; Branch if not
         LDX #$9A68      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Remake planner
C3E821:  CPY #$04F6      ; 1270?
         BNE C3E82B      ; Branch if not
         LDX #$9A80      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: System engineer (page 1)
C3E82B:  CPY #$069A      ; 1690?
         BNE C3E835      ; Branch if not
         LDX #$9A98      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: System engineer (page 2)
C3E835:  CPY #$083E      ; 2110?
         BNE C3E83F      ; Branch if not
         LDX #$9AB0      ; Source LBs
         JMP credx6      ; Init sprites

; Fork: Executive producer
C3E83F:  CPY #$09E2      ; 2530?
         BNE C3E847      ; Exit if not
         LDX #$9AC8      ; Source LBs
         JMP credx6      ; Init sprites
C3E847:  SEC             ; Set to requeue
         RTS

; Handle credits timing for aerial-view plains scene
C3E84A:  LDY $CF         ; Scene timer
         CPY #$00F0      ; 240?
         BNE C3E85B      ; Branch if not
         LDX #$9AE0      ; Source LBs
         JMP credx10     ; Init test coord

; Fork: Special thanks (page 1)
C3E85B:  CPY #$02D0      ; 720?
         BNE C3E865      ; Branch if not
         LDX #$9B08      ; Source LBs
         JMP credx10     ; Init sprites

; Fork: Special thanks (page 2)
C3E865:  CPY #$04B0      ; 1200?
         BNE C3E86F      ; Branch if not
         LDX #$9B30      ; Source LBs
         JMP credx9      ; Init sprites

; Fork: Special thanks (page 3)
C3E86F:  CPY #$0690      ; 1680?
         BNE C3E879      ; Branch if not
         LDX #$9B54      ; Source LBs
         BRA credx8      ; Init sprites

; Fork: Special thanks (page 4)
C3E879:  CPY #$0870      ; 2160?
         BNE C3E883      ; Branch if not
         LDX #$9B74      ; Source LBs
         BRA credx6      ; Init sprites

; Fork: Special thanks (page 5)
C3E883:  CPY #$0A50      ; 2640?
         BNE C3E88D      ; Branch if not
         LDX #$9B8C      ; Source LBs
         BRA credx5      ; Init sprites

; Fork: Special thanks (page 6)
C3E88D:  CPY #$0C30      ; 3120?
         BNE C3E847      ; Exit if not
         LDX #$9BA0      ; Source LBs
         BRA credx10     ; Init sprites

; Handle credits timing for rearview airship scene
C3E898:  LDY $CF         ; Scene timer
         CPY #$00F0      ; 240?
         BNE C3E8A9      ; Branch if not
         LDX #$9BC8      ; Source LBs
         BRA credx6      ; Init thanks_p7

; Fork: Special thanks (page 8)
C3E8A9:  CPY #$02D0      ; 720?
         BNE C3E8B3      ; Branch if not
         LDX #$9BE0      ; Source LBs
         BRA credx6      ; Init sprites

; Fork: Special thanks (page 9)
C3E8B3:  CPY #$04B0      ; 1200?
         BNE C3E8BD      ; Branch if not
         LDX #$9BF8      ; Source LBs
         BRA credx7      ; Init sprites

; Fork: Special thanks (page 10)
C3E8BD:  CPY #$0690      ; 1680?
         BNE C3E847      ; Exit if not
         LDX #$9C14      ; Source LBs
         BRA credx7      ; Init sprites

; Initialize credits (3 sprites)
credx3:  LDA #$03        ; Sprites: 3
         BRA C3EAF5      ; Init sprites

; Initialize credits (4 sprites)
credx4:  LDA #$04        ; Sprites: 4
         BRA C3EAF5      ; Init sprites

; Initialize credits (5 sprites)
credx5:  LDA #$05        ; Sprites: 5
         BRA C3EAF5      ; Init sprites

; Initialize credits (6 sprites)
credx6:  LDA #$06        ; Sprites: 6
         BRA C3EAF5      ; Init sprites

; Initialize credits (7 sprites)
credx7:  LDA #$07        ; Sprites: 7
         BRA C3EAF5      ; Init sprites

; Initialize credits (8 sprites)
credx8:  LDA #$08        ; Sprites: 8
         BRA C3EAF5      ; Init sprites

; Initialize credits (9 sprites)
credx9:  LDA #$09        ; Sprites: 9
         BRA C3EAF5      ; Init sprites

; Initialize credits (10 sprites)
credx10: LDA #$0A        ; Sprites: 10

; Initialize sprites for current credits strings
C3EAF5:  STA $FA         ; String count
         STX $F7         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $F9         ; Set src HB
         LDY $00         ; Index: 0
C3EAFD:  REP #$20        ; 16-bit A
         LDA [$F7],Y     ; Anim table ptr
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$F7],Y     ; Position
         STA $60         ; Memorize it
         SEP #$20        ; 8-bit A
         PHY             ; Save index
         TXY             ; Anim table ptr
         JSR C3EB64      ; Init sprite
         PLY             ; Table index
         INY             ; Index +1
         INY             ; Index +1
         DEC $FA         ; One less string
         BNE C3EAFD      ; Loop till last
         SEC             ; Set to requeue
         RTS

; Build credits' OAM table for sideview airship scene
C3E8C8:  LDX #$9DA4      ; Source LBs
         LDA #$01        ; Sprites: 1
         JSR C3EB18      ; Do position
         LDX #$9C30      ; Source LBs
         LDA #$02        ; Sprites: 2
         BRA C3EB38      ; Do staff

; Build credits' OAM table for aerial-view airship scene
C3E8DE:  LDX #$9DA8      ; Source LBs
         LDA #$0A        ; Sprites: 10
         JSR C3EB18      ; Do positions
         LDX #$9C38      ; Source LBs
         LDA #$18        ; Sprites: 24
         BRA C3EB38      ; Do staff

; Build credits' OAM table for boat scene
C3E8F4:  LDX #$9DD0      ; Source LBs
         LDA #$06        ; Sprites: 6
         JSR C3EB18      ; Do positions
         LDX #$9C98      ; Source LBs
         LDA #$10        ; Sprites: 16
         BRA C3EB38      ; Do staff

; Build credits' OAM table for skimming airship scene
C3E90A:  LDX #$9DE8      ; Source LBs
         LDA #$08        ; Sprites: 8
         JSR C3EB18      ; Do positions
         LDX #$9CD8      ; Source LBs
         LDA #$19        ; Sprites: 25
         BRA C3EB38      ; Do staff

; Build credits' OAM table for frontview airship scene
C3E920:  LDX #$9E08      ; Source LBs
         LDA #$08        ; Sprites: 8
         JSR C3EB18      ; Do positions
         LDX #$9D3C      ; Source LBs
         LDA #$1A        ; Sprites: 26
         BRA C3EB38      ; Do staff

; Build credits' OAM table for aerial-view plains scene
C3E936:  LDX #$9E28      ; Source LBs
         LDA #$3A        ; Sprites: 58
         BRA C3EB18      ; Build OAM

; Build credits' OAM table for rearview airship scene
C3E941:  LDX #$9F10      ; Source LBs
         LDA #$1A        ; Sprites: 26

; Build OAM table for scene's small credits strings
C3EB18:  JSR credini     ; Set src, index
C3EB1A:  LDX #$0B00      ; Adr MSB, pal 5
         JSR credptr     ; Init data
         CLC             ; Letter: 8x8
         JSR C3EC52      ; Build table
         LDY $FE         ; Pointer index
         DEC $4D         ; One less sprite
         BNE C3EB1A      ; Loop till last
         RTS

; Build OAM table for scene's large credits strings
C3EB38:  JSR credini     ; Set src, index
C3EB3A:  LDX #$0900      ; Adr MSB, pal 4
         JSR credptr     ; Init data
         SEC             ; Letter: 16x16
         JSR C3EC52      ; Build table
         LDY $FE         ; Pointer index
         DEC $4D         ; One less sprite
         BNE C3EB3A      ; Loop till last
         RTS

; Set pointer to OAM table for scene's credits strings
credini: STA $4D         ; String count
         STX $4A         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $4C         ; Set src HB
         LDY $00         ; Index: 0
         RTS

; Load pointers for credit string, etc.
credptr: STX $F1         ; Save attribs
         REP #$20        ; 16-bit A
         LDA [$4A],Y     ; Source LBs
         TAX             ; Save in X
         INY             ; Index +1
         INY             ; Index +1
         LDA [$4A],Y     ; Dest LBs
         INY             ; Index +1
         INY             ; Index +1
         STY $FE         ; Save index
         TAY             ; Dest LBs
         SEP #$20        ; 8-bit A
         JSR C3EC81      ; Set OAM tbl ptr
         LDY $00         ; Index: 0
         STA [$EB],Y     ; Set size
         INY             ; Index +1
         STZ $E0         ; Rel X: 0
;        STZ $EF         ; No use...
;        STZ $F0         ; No use...
         RTS

; Initialize sprite for current credit string
C3EB64:  STY $F1         ; Save anim ptr
         STZ $AF         ; Request fade-in
         LDY #C3EB94     ; C3/EB94
         JSR qanim0      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$01A4      ; Frames: 420
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         PEI ($60)       ; Coordinates
         PEI ($F1)       ; Anim ptr LBs
         LDA #$7E        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3F90X      ; Set sprite's

; Animate credit string
C3EB94:  BNE C3EBD4      ; If mode 1

; Mode 0: Initialize sprite
C3EB9C:  INC $3649,X     ; Mode +1
         LDA $344A,X     ; Sprite's Y
         CLC             ; Prepare ADC
         ADC #$20        ; Go 32 px down
         STA $344A,X     ; Save changes
         REP #$20        ; 16-bit A
         LDA #$FF80      ; V-Spd: -0.5 px
         STA $3549,X     ; Set sprite's
         STZ $34C9,X     ; H-Speed: 0
         JSR C31271      ; Set pose timer
         LDA $AF         ; Handled fade-in?
         BNE C3EBD4      ; Skip it if so
         PHB             ; Save DB
         LDA $B4         ; Text on clouds?
         BNE C3EBCC      ; Use blue if so
         JSR C3D675      ; Fade-in: White
         BRA C3EBCF      ; Skip a line
C3EBCC:  JSR C3D69C      ; Fade-in: Blue
C3EBCF:  LDA #$01        ; Mark as handled
         STA $AF         ; Allow fade-out
         PLB             ; Restore DB

; Mode 1: Sustain sprite
C3EBD4:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BEQ C3EBF9      ; Delete if so
         CPY #$0164      ; 356?
         BNE C3EBE6      ; Scroll if not
         STZ $3549,X     ; V-Speed LB: 0
         STZ $354A,X     ; V-Speed HB: 0
C3EBE6:  CPY #$0080      ; 128?
         BEQ C3EBFB      ; Fade if so
C3EBEB:  JSR C3EE10      ; Scroll & OAM
         JSR C3DF69      ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3EBF9:  CLC             ; Set to dequeue
         RTS

; Fork: Set to fade all text
C3EBFB:  LDA $AF         ; Already set?
         BEQ C3EBEB      ; Skip if so
         STZ $AF         ; Mark as handled
         PHB             ; Save DB
         JSR C3D64E      ; Trigger fade
         PLB             ; Restore DB
         BRA C3EBEB      ; Scroll & OAM

; Build OAM for credit letter
C3EC52:  LDA [$E7]       ; At terminator?
         BEQ C3EBF9      ; Exit if so
         PHP             ; Save size flag
         PHA             ; Save letter
         TDC             ; Clear A
         ROR A           ; #$80 if 16x16
         ORA $E0         ; Add relative X
         STA [$EB],Y     ; Set for letter
         INY             ; Index +1
         TDC             ; Relative Y: 0
         STA [$EB],Y     ; Set letter's
         INY             ; Index +1
         PLA             ; Letter
         REP #$21        ; 16-bit A; C-
         ADC $F1         ; Add attribs
         STA [$EB],Y     ; Set attribs
         INC $E7         ; Letter +1
         INY             ; Index +1
         INY             ; Index +1
         SEP #$21        ; 8-bit A; C+
         LDA $E0         ; Relative X
         ADC #$07        ; Go 8 px right
         STA $E0         ; Save changes
         PLP             ; Tile size flag
         BRA C3EC52      ; Do next letter

; Set OAM table pointer for credit string, compute string size
C3EC81:  STX $E7         ; Set src LBs
         LDA #$C2        ; Bank: C2
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         REP #$21        ; 16-bit A; C-
         LDA $EB         ; Dest LBs
         ADC #$0003      ; +3 bytes
         STA [$EB]       ; Set OAM ptr
         INC $EB         ; Dst LBs +1
         INC $EB         ; Dst LBs +1
         SEP #$20        ; 8-bit A
         LDA #$FE        ; Time: Infinite
         STA [$EB]       ; Set pose timer
         INC $EB         ; Dst LBs +1
         LDY $00         ; Letter: 1st
C3ECA5:  LDA [$E7],Y     ; Letter
         BEQ C3ECAF      ; If terminator
         INY             ; Index +1
         BRA C3ECA5      ; Do next letter
C3ECAF:  TYA             ; String size
         RTS

; Decompress data
C3ECB1:  STY $F3         ; Set src LBs
         STA $F5         ; Set src HB
         LDY #$C000      ; 7E/C000
         STY $F6         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $F8         ; Set dst HB
         JSL $C2FF6D     ; Unpack data
         RTS

; Clear VRAM
C3ECC3:  REP #$20        ; 16-bit A
         STZ $2116       ; VRAM: $0000
         LDA #$8000      ; Loop counter
         JMP C3BA80      ; Clear VRAM

; Convert and upload graphics for range of font characters
C3ECD6:  STY $2116       ; Set VRAM ptr
         STX $EB         ; Set data size
         STA $E9         ; Set src HB
         LDY $00         ; Index: 0
         REP #$20        ; 16-bit A
C3ECDD:  LDX #$0008      ; 8-px rows: 8
C3ECE0:  LDA [$E7],Y     ; 8 px, 2 planes
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         DEX             ; One less row
         BNE C3ECE0      ; Loop till last
         LDX #$0008      ; 8-px rows: 8
.loop    STZ $2118       ; Planes C and D
         DEX             ; One less row
         BNE .loop       ; Loop till last
         CPY $EB         ; More tiles?
         BNE C3ECDD      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Upload data manually, adjust attributes if tilemap
C3ED0_:  STZ $ED         ; Attrib LB: 0
         STZ $EE         ; Attrib HB: 0
C3ED09:  REP #$20        ; 16-bit A
         STY $2116       ; Set VRAM ptr
         STX $EB         ; Set data size
         LDY $00         ; Index: 0
C3ED11:  LDA [$E7],Y     ; Source data
         CLC             ; Prepare ADC
         ADC $ED         ; Add attribs
         STA $2118       ; Save in VRAM
         INY             ; Index +1
         INY             ; Index +1
         CPY $EB         ; Past range?
         BNE C3ED11      ; Loop if not
         SEP #$20        ; 8-bit A
         RTS

; Build Mode 7 matrix tables for HDMA
C3ED22:  PHB             ; Save DB
         TDC             ; Bank: 00
         PHA             ; Put on stack
         PLB             ; Set DB to 0

; Fork: Define scale dividend
C3ED29:  LDA $C3         ; Dividend index
         JSR C3EDC6      ; Signed dividend
;        STA $E0         ; ...
         STA $EB         ; Memorize it
;        LDA $E0         ; Positive?
         BPL C3ED3A      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3ED3A:  LSR A           ; Halve it
         STA $CB         ; Save dividend

; Fork: Define shear dividend
C3ED3F:  LDA $C3         ; Dividend index
         JSR C3EDCA      ; Signed dividend
;        STA $E0         ; ...
         STA $ED         ; Memorize it
;        LDA $E0         ; Positive?
         BPL C3ED50      ; Branch if so
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
C3ED50:  LSR A           ; Halve it
         STA $C9         ; Save dividend

; Fork: Define matrices A and D for two scanlines
C3ED55:  LDY #$01C0      ; Scanline: Last
         LDA $C5         ; Base divisor
         STA $E7         ; Memorize it
C3ED5C:  LDA $CB         ; Scale dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         JSR x32r        ; 16-bit A; cycles
         LDA $EB         ; Positive mod?
         BPL C3ED7C      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert value
         INC A           ; Add 1
         BRA C3ED7F      ; Skip a line
C3ED7C:  LDA $4214       ; Quotient
C3ED7F:  STA $0602,Y     ; Set line 1
         STA $0604,Y     ; Set line 2

; Fork: Define matrices B and C for two scanlines
C3ED85:  LDA $C9         ; Shear dividend
         STA $4204       ; To register
         SEP #$20        ; 8-bit A
         LDA $E8         ; Map factor HB
         STA $4206       ; Set divisor
         JSR x32r        ; 16-bit A; cycles
         LDA $E7         ; Matrix divisor
         SEC             ; Prepare SBC
         SBC $C7         ; Deduct "angle"
         STA $E7         ; Save changes
         LDA $ED         ; Positive mod?
         BPL C3EDA9      ; Branch if so
         LDA $4214       ; Quotient
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         BRA C3EDAC      ; Skip a line
C3EDA9:  LDA $4214       ; Quotient
C3EDAC:  STA $07C4,Y     ; Set line B1
         STA $07C6,Y     ; Set line B2
         EOR #$FFFF      ; Invert it
         INC A           ; Add 1
         STA $0986,Y     ; Set line C1
         STA $0988,Y     ; Set line C2
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         DEY             ; Index -1
         BPL C3ED5C      ; Loop if > 0
         SEP #$20        ; 8-bit A
         PLB             ; Restore DB
         RTS

; Load animation modifier
C3EDC6:  REP #$21        ; 16-bit A; C-
         ADC #$0040      ; Index +64
C3EDCA:  AND #$00FF      ; Clear HB
         ASL A           ; Double it
         TAX             ; Index it
         LDA $C2FC6D,X   ; Modifier
         RTS

; Animate linearly moving temporary sprite
C3EDD4:  BNE C3EDE4      ; If mode 1

; Mode 0: Initialize timer
C3EDDC:  JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain sprite
C3EDE4:  LDY $3349,X     ; Timer expired?
         BEQ C3EDF9      ; Delete if so
         JSR C3EE10      ; Scroll & OAM
         JSR C3DF69      ; Timer -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3EDF9:  CLC             ; Set to dequeue
         RTS

; Animate regular permanent sprite
C3EDFB:  BNE C3EE0B      ; If mode 1

; Mode 0: Initialize timer
C3EE03:  JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1

; Mode 1: Sustain sprite
C3EE0B:  JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Scroll sprite and define OAM
C3EE10:  LDX $2D         ; Queue index
         REP #$21        ; 16-bit A; C-
         LDA $33C9,X     ; Fractional X
         ADC $34C9,X     ; Add H-Speed
         STA $33C9,X     ; Save changes
         LDA $3449,X     ; Fractional Y
         CLC             ; Prepare ADC
         ADC $3549,X     ; Add V-Speed
         STA $3449,X     ; Save changes
         JMP C3128C      ; Define OAM

; Animate true actor name or "And you"
C3EE2D:  STA $E0         ; Save mode
         LDA $47         ; At 2nd actor?
         BNE C3EE4D      ; Delete if so
         LDA $E0         ; Anim mode
         TAX             ; Index it
         JMP (C3EE3B,X)  ; Handle mode

; Jump table for the above
C3EE3B:  dw C3EE4F       ; Initialize sprite
         dw C3EE63       ; Refresh sprite
         dw C3EE6B       ; Set to scroll up
         dw C3EE63       ; Refresh sprite
         dw C3EE73       ; Stop scrolling
         dw C3EE63       ; Refresh sprite
         dw C3EE7A       ; Set to scroll up
         dw C3EE63       ; Refresh sprite
         dw C3EE4D       ; Delete sprite

; Mode 8: Delete sprite
C3EE4D:  CLC             ; Set to dequeue
         RTS

; Mode 0: Initialize sprite
C3EE4F:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         STZ $3549,X     ; V-Speed: 0
         LDA $85         ; Scroll delay
         STA $3349,X     ; Set mode timer
         JSR C31271      ; Set pose timer

; Modes 1, 3, 5: Refresh sprite
C3EE63:  JSR C3EE9B      ; Mode timer -1
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Mode 2: Set to scroll upward 2.5s
C3EE6B:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$0096      ; Frames: 150
         BRA C3EE82      ; Set spd, timer

; Mode 4: Stop scrolling
C3EE73:  LDY $00         ; V-Speed: 0
         LDX #$00F0      ; Frames: 240
         BRA C3EE82      ; Set spd, timer

; Mode 6: Set to scroll upward 5s
C3EE7A:  LDY #$FFC0      ; V-Spd: -0.25 px
         LDX #$012C      ; Frames: 300

; Fork: Change V-Speed and mode timer
C3EE82:  PHX             ; Save timer
         LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         TYA             ; V-Speed
         STA $3549,X     ; Set sprite's
         PLA             ; Mode timer
         STA $3349,X     ; Set sprite's
         BRA C3EE63      ; Scroll & OAM

; Decrease animation timer, advance mode if expired
C3EE9B:  LDX $2D         ; Queue index
         REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BNE C3EEA9      ; Branch if not
         INC $3649,X     ; Mode +1
         BRA C3EEAC      ; Skip a line
C3EEA9:  DEC $3349,X     ; Timer -1
C3EEAC:  SEP #$20        ; 8-bit A
         RTS

; Draw, center, and set to upload actor's pseudonym
C3EEAF:  LDY $00         ; 1st: Terra
C3EEB1:  STY $EB         ; Save slot
         REP #$20        ; 16-bit A
         TYA             ; Actor slot
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C370DB,X  ; Actor's address
         TAY             ; Index it
         SEP #$20        ; 8-bit A
         LDA $0000,Y     ; Actor in slot
         CMP $28         ; Matches ours?
         BEQ C3EEE9      ; Proceed if so
         LDY $EB         ; Actor slot
         INY             ; Actor slot +1
         CPY #$0010      ; Done all 16?
         BNE C3EEB1      ; Loop if not

; Fork: Default to "??????" (Gogo, Umaro)
C3EED9:  LDX $00         ; Dst index: 0
         LDA.B #!ques    ; Char: "?"
C3EEDD:  STA $7E9E89,X   ; Add to string
         INX             ; Index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3EEDD      ; Loop if not
         BRA C3EEF9      ; Skip alt case

; Fork: Load actor's name
C3EEE9:  LDX $00         ; Dst index: 0
C3EEEB:  LDA $0002,Y     ; Letter
         STA $7E9E89,X   ; Add to string
         INY             ; Src index +1
         INX             ; Dst index +1
         CPX #$0006      ; Done 6 chars?
         BNE C3EEEB      ; Loop if not
C3EEF9:  JSR C3EF03      ; Center name
         JSR C3AF6E      ; Build tilemap
         JMP C3AF98      ; Load graphics

; Center BG3 camera on actor's pseudonym
C3EF03:  LDX $00         ; Letter: 1st
         TXY             ; Space count: 0
C3EF06:  LDA $7E9E89,X   ; Letter
;        STA $7E9E93,X   ; No use...
         CMP #$FF        ; Space char?
         BNE C3EF13      ; Skip if not
         INY             ; Space count +1
C3EF13:  INX             ; Char index +1
         CPX #$0006      ; Done all 6?
         BNE C3EF06      ; Loop if not
         REP #$20        ; 16-bit A
         TYA             ; Space count
         ASL A           ; x2
         ASL A           ; x4 pixels
         EOR #$FFFF      ; Invert value
         INC A           ; Add one
         STA $3D         ; Set BG3 X-Pos
         SEP #$20        ; 8-bit A
         RTS

; Temporarily scroll BG1 westward
C3EF3C:  REP #$20        ; 16-bit A
         LDA $3349,X     ; Timer expired?
         BEQ C3EF58      ; Dequeue if so
         DEC $3349,X     ; Timer -1
         SEP #$20        ; 8-bit A
         LDA $23         ; NMI count
         AND #$03        ; Now 0-3
         BNE C3EF56      ; Pause if > 0
         REP #$20        ; 16-bit A
         INC $35         ; BG1 X-Pos +1
C3EF56:  SEC             ; Set to requeue
         RTS             ; Exit
C3EF58:  CLC             ; Set to dequeue
         RTS

; Create actor's first and last names
C3EF5C:  LDA $28         ; Actor
         XBA             ; Put it in B
         LDA #$06        ; Name data size
         JSR mul8        ; Actor x size
         TAX             ; Index product
         REP #$20        ; 16-bit A
         LDA $C28DD4,X   ; Anim ptr A
         TAY             ; Put in Y
         LDA $C28DD7,X   ; Anim ptr B
         PHA             ; Memorize it
         SEP #$20        ; 8-bit A
         LDA $C28DD6,X   ; Name A's X
         PHA             ; Memorize it
         LDA $C28DD9,X   ; Name B's X
         STA $54         ; Memorize it
         LDA #$C2        ; Anim ptr HB
         JSR C3EFC9      ; Create name A
         PLA             ; X position
         STA $7E33CA,X   ; Set name A's
         LDA #$C2        ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR C3EFC9      ; Create name B
         LDA $54         ; X position
         STA $7E33CA,X   ; Set name B's
         RTS

; Create true actor name or "And you"
C3EFC9:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3EE2D     ; C3/EE2D
         JSR qanim1      ; Queue anim fn
         LDA #$D0        ; Y: 208
         STA $7E344A,X   ; Set sprite's
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set sprite's

; Create "And you"
C3EFD2:  LDA #$CF        ; Anim ptr HB
         LDY #$F85B      ; Anim ptr LBs
         JSR C3EFC9      ; Create sprite
         LDA #$68        ; X: 104
         STA $7E33CA,X   ; Set sprite's
         RTS

; Initialize font, BG, and register data for actor scene
C3EFF3:  STA $28         ; Set actor slot
         JSL $D4CE8C     ; Init registers
         JSR C371D0      ; Clear BG3 A
         JSR C371BC      ; Clear BG2 A
         LDY #$3049      ; To BG pal 0
         JSR black       ; BGP0: Black
         LDY #$3069      ; To BG pal 1
         JSR black       ; BGP1: Black
         LDY #$3089      ; To BG pal 2
         JSR black       ; BGP2: Black
         LDY #$30E9      ; To BG pal 5
         JSR black       ; BGP5: Black
         LDY #$3109      ; To BG pal 6
         JSR black       ; BGP6: Black
         LDY #$3149      ; To OBJ pal 0
         JSR black       ; OBP0: Black
         LDY #$3169      ; To OBJ pal 1
         JSR black       ; OBP1: Black
         LDY #$31C9      ; To OBJ pal 4
         JSR black       ; OBP4: Black
         JSR C3FDAE      ; Load big font
         JMP C3FDCA      ; And BG GFX/map

; Create and upload text for actor scene, unblank screen
C3F05D:  STZ $47         ; Erase name: N
         JSR C3F7D1      ; Create "as"
;        LDA #$2C        ; Palette 3
;        STA $29         ; No use...
         JSR C3EEAF      ; Create alias
         LDA #$01        ; CGRAM: Freeze
         TRB $45         ; Set NMI flag
         JSR C31517      ; Upload alias
         LDA #$01        ; CGRAM: Refresh
         TSB $45         ; Set NMI flag
         JSR C3EF5C      ; Create true name
C3F077:  JSR C3FE5B      ; Queue BG1+BG3a
         INC $26         ; Scene mode +1
         JMP C3D5E7      ; Set brightness

; Set to fade BG elements for actor scene (also final airship's)
C3F07F:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDY #$30E9      ; To BG pal 5
         LDX #C3115F     ; Black palette
         JSR slow4       ; Do tabletop
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3109      ; To BG pal 6
         LDX #C3115F     ; Black palette
         JSR slow4       ; Do overlay
C3F0A5:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDY #$3069      ; To BG pal 1
         LDX #C3115F     ; Black palette
         JSR slow4       ; Do book, etc.
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3089      ; To BG pal 2
         LDX #C3115F     ; Black palette
         JMP slow4       ; Do bones, etc.

; Set to fade in BG elements for actor scene
C3F0CC:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3069      ; To BG pal 1
         LDX #$9674      ; C2/9674
         JSR slow2       ; Do book, etc.
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3089      ; To BG pal 2
         LDX #$9694      ; C2/9694
         JSR slow2       ; Do bones, etc.
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$30E9      ; To BG pal 5
         LDX #$96D4      ; C2/96D4
         JSR slow2       ; Do tabletop
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3109      ; To BG pal 6
         LDX #$96F4      ; C2/96F4
         JMP slow2       ; Do overlay

; Set to fade in actor's pseudonym and "as"
C3F119:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3049      ; To BG pal 0
         LDX #$974C      ; C2/974C
         JSR slow4       ; Handle name
;        LDA #$C2        ; ...
;        STA $ED         ; ...
         LDY #$3169      ; To OBJ pal 1
         LDX #$974C      ; C2/974C
         JMP slow4       ; Handle "as"

; Set to scroll and fade actor alias, fade "as", fade in true name
C3F140:  STZ $CF         ; Scroll timer LB
         STZ $D0         ; Scroll timer HB
         LDY #$00F0      ; Frames: 240
         STY $64         ; Set scroll limit
         LDY #C3E13A     ; C3/E13A
         JSR qanim0      ; Queue scroll fn
         JSR C3F17B      ; Fade pseudonym
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3169      ; To OBJ pal 1
         LDX #C3115F     ; Black palette
         JSR slow4       ; Fade "as"
C3F167:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3149      ; To OBJ pal 0
         LDX #$974C      ; C2/974C
         JMP slow4       ; Fade in true name

; Set to fade background palette 0
C3F17B:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDY #$3049      ; To BG pal 0
         LDX #C3115F     ; Black palette
         JMP slow4       ; Queue fade-out

; Set to fade sprite palette 0
C3F18F:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDY #$3149      ; To OBJ pal 0
         LDX #C3115F     ; Black palette
         JMP slow4       ; Queue fade-out

; 28: Start Shadow's scene
C3F1A8:  LDA #$03        ; Actor: Shadow
         JSR C3EFF3      ; Init BGs/font
         JSR C3FE82      ; Upload apple
         JSR C3F0CC      ; Fade in BGs
         JSR C3F1C4      ; Fade in apple
         JSR C3F779      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JSR C3F8ED      ; Create apple
         JMP C3F05D      ; Create text

; Set to fade in non-glint sprites on table
C3F1C4:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #$976C      ; C2/976C
         JMP slow2       ; Queue fade-in

; Set to fade sprite palette 4
C3F1D8:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDY #$31C9      ; To OBJ pal 4
         LDX #C3115F     ; Black palette
         JMP slow4       ; Queue fade-out

; 29: Fade in "Shadow as"
C3F1EC:  LDY $20         ; Delay expired?
         BNE C3F1FA      ; Exit if not
         INC $26         ; Next: C3/F1FB
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F1FA:  RTS

; 2A: Switch Shadow's names
C3F1FB:  LDY $20         ; Delay expired?
         BNE C3F209      ; Exit if not
         INC $26         ; Next: C3/F20A
         JSR C3F140      ; Switch names
         LDY #$0168      ; Fade/Pan delay
         STY $20         ; Set for below
C3F209:  RTS

; 2B: Fade all but Shadow's name
C3F20A:  LDY $20         ; Delay expired?
         BNE C3F209      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade apple
         JMP C3F77F      ; Scroll table

; 38: Fade actor's true name
C3F221:  LDY $20         ; Delay expired?
         BNE C3F209      ; Exit if not
         LDA #$78        ; Frames: 120
         STA $20         ; Set exit delay
         LDA #$01        ; C3/D543
         STA $26         ; Next: Exit
         JMP C3F18F      ; Queue fade-out

; 32: Start Cyan's scene
C3F232:  LDA #$02        ; Actor: Cyan
         JSR C3EFF3      ; Init BGs/font
         JSR C3FEA2      ; Draw sword; GFX
         JSR C3F0CC      ; Fade in BGs
         JSR C3F3A2      ; Fade in glint
         LDY #$FFB8      ; X: -72 = 440
         STY $35         ; Set BG1 X-Pos
         JSR C3F773      ; Scroll table
         LDY #C3FBE8     ; C3/FBE8
         JSR qanim0      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3F05D      ; Create text

; 33: Fade in "Cyan as"
C3F253:  LDY $20         ; Delay expired?
         BNE C3F261      ; Exit if not
         INC $26         ; Next: C3/F262
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F261:  RTS

; 34: Switch Cyan's names
C3F262:  LDY $20         ; Delay expired?
         BNE C3F270      ; Exit if not
         INC $26         ; Next: C3/F271
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F270:  RTS

; 35: Fade all but Cyan's name
C3F271:  LDY $20         ; Delay expired?
         BNE C3F270      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JMP C3F1D8      ; Fade glint

; 40: Start Edgar and Sabin's scene
C3F285:  LDA #$04        ; Actor: Edgar
         JSR C3EFF3      ; Init BGs/font
         JSR C3FEB8      ; Upload coin
         JSR C3F0CC      ; Fade in BGs
         JSR C3F1C4      ; Fade in coin
         LDY #C3FC73     ; C3/FC73
         JSR qanim2      ; Queue coin fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 41: Fade in "Edgar as"
C3F29E:  LDY $20         ; Delay expired?
         BNE C3F2AC      ; Exit if not
         INC $26         ; Next: C3/F2AD
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for alias
C3F2AC:  RTS

; 42: Switch Edgar's names
C3F2AD:  LDY $20         ; Delay expired?
         BNE C3F2BB      ; Exit if not
         INC $26         ; Next: C3/F2BC
         JSR C3F140      ; Switch names
         LDA #$F0        ; Intro delay
         STA $20         ; Set for Sabin
C3F2BB:  RTS

; 43: Show Sabin's name, fade Edgar's
C3F2BC:  LDY $20         ; Delay expired?
         BNE C3F2DB      ; Exit if not
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$05        ; Actor: Sabin
         STA $28         ; Set actor slot
         JSR C3F7D1      ; Create "as"
         JSR C3F18F      ; Fade Edgar
         JSR C3EEAF      ; Create Sabin
         JSR C3F119      ; Fade in Sabin
         INC $26         ; Next: C3/F2DC
         LDA #$78        ; Removal delay
         STA $20         ; Set for Edgar
C3F2DB:  RTS

; 44: Delete Edgar's name
C3F2DC:  LDY $20         ; Delay expired?
         BNE C3F2EB      ; Exit if not
         INC $47         ; Erase name: Y
         INC $26         ; Next: C3/F2EC
         LDA #$B4        ; Switch delay
         STA $20         ; Set for Sabin
C3F2EB:  RTS

; 45: Switch Sabin's names
C3F2EC:  LDY $20         ; Delay expired?
         BNE C3F2EB      ; Exit if not
         LDA #$4F        ; C3/F307
         STA $26         ; Next: Fade BG
         LDA #$B4        ; Frames: 180
         STA $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3EF5C      ; Create true name
         JMP C3F140      ; Switch names

; 4F: Fade all but Sabin's name
C3F307:  LDY $20         ; Delay expired?
         BNE C3F2EB      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JMP C3F1D8      ; Fade coin

; 3C: Start Mog's scene
C3F31B:  LDA #$0A        ; Actor: Mog
         JSR C3EFF3      ; Init BGs/font
         JSR C3FEDC      ; Draw tree; GFX
         JSR C3F0CC      ; Fade in BGs
         JSR C3F1C4      ; Fade in sprites
         JSR C3F779      ; Scroll table
         JSR C3F95E      ; Create sprites
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 3D: Fade in "Mog as"
C3F337:  LDY $20         ; Delay expired?
         BNE C3F345      ; Exit if not
         INC $26         ; Next: C3/F346
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F345:  RTS

; 3E: Switch Mog's names
C3F346:  LDY $20         ; Delay expired?
         BNE C3F354      ; Exit if not
         INC $26         ; Next: C3/F355
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F354:  RTS

; 3F: Fade all but Mog's name
C3F355:  LDY $20         ; Delay expired?
         BNE C3F354      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade sprites
         JMP C3F77F      ; Scroll table

; 46: Start Gogo's scene
C3F36C:  LDA #$0C        ; Actor: Gogo
         JSR C3EFF3      ; Init BGs/font
         JSR C3FEF2      ; Draw helmet; eye
         JSR C3F0CC      ; Fade in BGs
         JSR C3F773      ; Scroll table
         JSR C3F91E      ; Create pink eye
         LDY #C3F3D9     ; C3/F3D9
         JSR qanim2      ; Queue eye fn
         LDA #$B4        ; Frames: 180
         STA $7E3349,X   ; Set eye delay
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 47: Fade in "Gogo as"
C3F393:  LDY $20         ; Delay expired?
         BNE C3F3A1      ; Exit if not
         INC $26         ; Next: C3/F3B6
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for nameS
C3F3A1:  RTS

; Set to fade in glint on table object
C3F3A2:  LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9554      ; C2/9554
         JMP C31015      ; Queue fade-in

; 48: Switch Gogo's names
C3F3B6:  LDY $20         ; Delay expired?
         BNE C3F3C4      ; Exit if not
         INC $26         ; Next: C3/F3C5
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F3C4:  RTS

; 49: Fade all but Gogo's name
C3F3C5:  LDY $20         ; Delay expired?
         BNE C3F3C4      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JMP C3F1D8      ; Fade eye

; Animate eye in Gogo's helmet
C3F3D9:  CMP #$02        ; Mode 1?
         BEQ C3F3F4      ; Branch if so
         CMP #$06        ; Mode 3?
         BEQ C3F419      ; Branch if so

; Modes 0 and 2: Wait
C3F3E5:  LDA $3349,X     ; Timer expired?
         BNE C3F3EF      ; Branch if not
         INC $3649,X     ; Mode +1
C3F3EF:  DEC $3349,X     ; Timer -1
         SEC             ; Set to requeue
         RTS

; Mode 1: Fade in eye
C3F3F4:  PHB             ; Save DB
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #$9574      ; C2/9574
         JSR C31015      ; Queue fade-in
         PLB             ; Restore DB
         LDX $2D         ; Queue index
         LDA #$3C        ; Delay: 60
         STA $3349,X     ; Set fade-out's
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 3: Fade out eye
C3F419:  LDA #$C3        ; C3/115F
         STA $ED         ; Set src HB
         LDA #$01        ; Slowness: 1
         LDY #$31C9      ; To OBJ pal 4
         LDX #C3115F     ; Black palette
         JSR C31015      ; Queue fade
         CLC             ; Set to dequeue
         RTS

; 50: Start Gau's scene
C3F434:  LDA #$0B        ; Actor: Gau
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF08      ; Draw helmet; face
         JSR C3F0CC      ; Fade in BGs
         JSR C3F1C4      ; Fade in face
         JSR C3F779      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 51: Fade in "Gau as"
C3F44D:  LDY $20         ; Delay expired?
         BNE C3F46D      ; Exit if not
         INC $26         ; Next: C3/F45C
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
         JMP C3F119      ; Queue fade-in

; 52: Switch Gau's names; create face
C3F45C:  LDY $20         ; Delay expired?
         BNE C3F46D      ; Exit if not
         INC $26         ; Next: C3/F46E
         JSR C3F8CE      ; Create face
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F46D:  RTS

; 53: Fade all but Gau's name
C3F46E:  LDY $20         ; Delay expired?
         BNE C3F46D      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade face
         JMP C3F77F      ; Scroll table

; 5A: Start Terra's scene
C3F485:  TDC             ; Actor: Terra
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF1E      ; Draw glass; GFX
         JSR C3F0CC      ; Fade in BGs
         JSR C3F3A2      ; Fade in glint
         JSR C3F779      ; Scroll table
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 5B: Fade in "Terra as"
C3F49E:  LDY $20         ; Delay expired?
         BNE C3F4BE      ; Exit if not
         INC $26         ; Next: C3/F4AD
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
         JMP C3F119      ; Queue fade-in

; 5C: Switch Terra's names, create glint
C3F4AD:  LDY $20         ; Delay expired?
         BNE C3F4BE      ; Exit if not
         INC $26         ; Next: C3/F4BF
         JSR C3F93D      ; Create glint
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F4BE:  RTS

; 5D: Fade all but Terra's name
C3F4BF:  LDY $20         ; Delay expired?
         BNE C3F4BE      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade glint
         JMP C3F77F      ; Scroll table

; 64: Start Locke and Celes's scene
C3F4D6:  LDA #$01        ; Actor: Locke
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF34      ; Draw bouquet
         JSR C3F0CC      ; Fade in BGs
         JSR C3F779      ; Scroll table
         LDY #$FFE0      ; X: -32 = 480
         STY $35         ; Set BG1 X-Pos
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 65: Fade in "Locke as"
C3F4F1:  LDY $20         ; Delay expired?
         BNE C3F50E      ; Exit if not
         INC $26         ; Next: C3/F500
         LDA #$F0        ; Switch delay
         STA $20         ; Set for alias
         JMP C3F119      ; Queue fade-in

; 66: Switch Locke's names
C3F500:  LDY $20         ; Delay expired?
         BNE C3F50E      ; Exit if not
         INC $26         ; Next: C3/F50F
         JSR C3F140      ; Switch names
         LDA #$F0        ; Intro delay
         STA $20         ; Set for Celes
C3F50E:  RTS

; 67: Show Celes's name, fade Locke's
C3F50F:  LDY $20         ; Delay expired?
         BNE C3F52E      ; Exit if not
         STY $3F         ; BG3 Y-Pos: 0
         LDA #$06        ; Actor: Celes
         STA $28         ; Set actor slot
         JSR C3F7D1      ; Create "as"
         JSR C3F18F      ; Fade Locke
         JSR C3EEAF      ; Create Celes
         JSR C3F119      ; Fade in Celes
         INC $26         ; Next: C3/F52F
         LDA #$78        ; Removal delay
         STA $20         ; Set for Locke
C3F52E:  RTS

; 68: Delete Locke's name
C3F52F:  LDY $20         ; Delay expired?
         BNE C3F53E      ; Exit if not
         INC $47         ; Erase name: Y
         INC $26         ; Next: C3/F53F
         LDA #$B4        ; Switch delay
         STA $20         ; Set for Celes
C3F53E:  RTS

; 69: Switch Celes's names
C3F53F:  LDY $20         ; Delay expired?
         BNE C3F53E      ; Exit if not
         INC $26         ; Next: C3/F558
         LDA #$B4        ; Frames: 180
         STA $20         ; Set fade delay
         STZ $47         ; Erase name: N
         LDY #$0014      ; Frames: 20
         STY $85         ; Set scroll delay
         JSR C3EF5C      ; Create true name
         JMP C3F140      ; Switch names

; 6A: Fade all but Celes's name
C3F558:  LDY $20         ; Delay expired?
         BNE C3F53E      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
;        JSR C3F1D8      ; No sprites...
         JMP C3F77F      ; Scroll table

; 6E: Start Relm's scene
C3F56F:  LDA #$08        ; Actor: Relm
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF47      ; Draw brush; GFX
         JSR C3F0CC      ; Fade in BGs
         JSR C3F3A2      ; Fade in glint
         JSR C3F779      ; Scroll table
         LDY #C3FB82     ; C3/FB82
         JSR qanim0      ; Queue glints
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 6F: Fade in "Relm as"
C3F58B:  LDY $20         ; Delay expired?
         BNE C3F599      ; Exit if not
         INC $26         ; Next: C3/F59A
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F599:  RTS

; 70: Switch Relm's names
C3F59A:  LDY $20         ; Delay expired?
         BNE C3F5A8      ; Exit if not
         INC $26         ; Next: C3/F5A9
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F5A8:  RTS

; 71: Fade all but Relm's name
C3F5A9:  LDY $20         ; Delay expired?
         BNE C3F5A8      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade glint
         JMP C3F77F      ; Scroll table

; 78: Start Strago's scene
C3F5C0:  LDA #$07        ; Actor: Strago
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF5D      ; Draw book
         JSR C3F0CC      ; Fade in BGs
         JSR C3FCB9      ; Queue book fn
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for name
         JMP C3F05D      ; Create text

; 79: Fade in "Strago as"
C3F5D6:  LDY $20         ; Delay expired?
         BNE C3F5E4      ; Exit if not
         INC $26         ; Next: C3/F5E5
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F5E4:  RTS

; 7A: Switch Strago's names
C3F5E5:  LDY $20         ; Delay expired?
         BNE C3F5F3      ; Exit if not
         INC $26         ; Next: C3/F5F4
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F5F3:  RTS

; 7B: Fade all but Strago's name
C3F5F4:  LDY $20         ; Delay expired?
         BNE C3F5F3      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
;        JSR C3F1D8      ; No sprites...
         JMP C3F07F      ; Fade BGs

; 2D: Start first book scene
C3F608:  JSR C3EFF3      ; Init BGs/font
         JSR C3FF5D      ; Draw book
         JSR C3F0CC      ; Fade in BGs
         LDY #$02D0      ; Frames: 720
         STY $20         ; Set anim delay
         JMP C3F077      ; Queue BG1, etc.

; 2E: Animate first book
C3F619:  LDY $20         ; Delay expired?
         BNE C3F627      ; Exit if not
         INC $26         ; Next: C3/F628
         JSR C3FCCE      ; Queue book fn
         LDY #$01E0      ; Frames: 480
         STY $20         ; Set wait timer
C3F627:  RTS

; 2F: Wait 480 frames
C3F628:  LDY $20         ; Delay expired?
         BNE C3F633      ; Exit if not
         INC $26         ; Next: C3/F634
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F633:  RTS

; 30: Pixelate and fade first book
C3F634:  LDY $20         ; Delay expired?
         BNE C3F633      ; Exit if not
         JSR C3F785      ; Queue mosaic
         LDA #$78        ; Frames: 120x2
         STA $20         ; Set exit delay
         JSR C3F07F      ; Fade BGs
         JMP C3F77F      ; Scroll table

; 4A: Start last book scene
C3F64B:  JSR C3EFF3      ; Init BGs/font
         JSR C3FF5D      ; Draw book
         JSR C3F0CC      ; Fade in BGs
         JSR C3FCE3      ; Queue book fn
         LDA #$B4        ; Frames: 180
         STA $20         ; Set wait timer
         STZ $47         ; Erase text: N
         JSR C3EFD2      ; Create "And you"
         JMP C3F077      ; Queue BG1, etc.

; 4B: Wait 180 frames
C3F664:  LDY $20         ; Delay expired?
         BNE C3F66F      ; Exit if not
         INC $26         ; Next: C3/F670
         LDA #$EC        ; Freeze delay
         STA $20         ; Set for book
C3F66F:  RTS

; 4C: Stop last book and fade in text
C3F670:  LDY $20         ; Delay expired?
         BNE C3F66F      ; Exit if not
         LDA #$01        ; Last page: Y
         STA $99         ; Set book flag
         INC $26         ; Next: C3/F683
         LDY #$016C      ; Frames: 364
         STY $20         ; Set fade delay
         JMP C3F167      ; Queue fade-in

; 4D: Pixelate and fade last book
C3F683:  LDY $20         ; Delay expired?
         BNE C3F66F      ; Exit if not
         JSR C3F785      ; Queue mosaic
         LDA #$78        ; Fade delay
         STA $20         ; Set for text
         JMP C3F07F      ; Fade BGs

; 82: Start Setzer's scene
C3F697:  LDA #$09        ; Actor: Setzer
         JSR C3EFF3      ; Init BGs/font
         JSR C3FF70      ; Upload cards
         JSR C3F0CC      ; Fade in BGs
         LDY #$3189      ; To OBJ pal 2
         JSR black       ; Cards: Black
         LDA #$C2        ; Bank: C2
         STA $ED         ; Set src HB
         LDY #$3189      ; To OBJ pal 2
         LDX #$976C      ; C2/976C
         JSR slow2       ; Fade in cards
         JSR C3F773      ; Scroll table
         JSR C3F81D      ; Create cards
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3F05D      ; Create text

; 83: Fade in "Setzer as"
C3F6CE:  LDY $20         ; Delay expired?
         BNE C3F6DC      ; Exit if not
         INC $26         ; Next: C3/F6DD
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F6DC:  RTS

; 84: Switch Setzer's names
C3F6DD:  LDY $20         ; Delay expired?
         BNE C3F6EB      ; Exit if not
         INC $26         ; Next: C3/F6EC
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F6EB:  RTS

; 85: Fade background
C3F6EC:  LDY $20         ; Delay expired?
         BNE C3F6EB      ; Exit if not
         INC $26         ; Next: C3/F6FB
         LDA #$78        ; Fade delay
         STA $20         ; Set for cards
         JMP C3F07F      ; Fade BGs

; 86: Fade cards and name
C3F6FB:  LDY $20         ; Delay expired?
         BNE C3F6EB      ; Exit if not
         LDA #$78        ; Frames: 120
         STA $20         ; Set exit delay
         LDA #$01        ; C3/D543
         STA $26         ; Next: Exit
         JSR C3F18F      ; Fade name
;        LDA #$C3        ; ...
;        STA $ED         ; ...
         LDY #$3189      ; To OBJ pal 2
         LDX #C3115F     ; Black palette
         JMP slow4       ; Fade cards

; 87: Start Umaro's scene
C3F71F:  LDA #$0D        ; Actor: Umaro
         JSR C3EFF3      ; Init BGs/font
         JSR C3FFAC      ; Draw bones; GFX
         JSR C3F0CC      ; Fade in BGs
         JSR C3F1C4      ; Fade in sprites
         JSR C3F779      ; Scroll table
         JSR C3F7FE      ; Create skull
         JSR C3F9B6      ; Create moogles
         LDY #$0078      ; Fade-in delay
         STY $20         ; Set for alias
         JMP C3F05D      ; Create text

; 88: Fade in "Umaro as"
C3F73E:  LDY $20         ; Delay expired?
         BNE C3F74C      ; Exit if not
         INC $26         ; Next: C3/F74D
         JSR C3F119      ; Queue fade-in
         LDA #$F0        ; Switch delay
         STA $20         ; Set for names
C3F74C:  RTS

; 89: Switch Umaro's names
C3F74D:  LDY $20         ; Delay expired?
         BNE C3F75B      ; Exit if not
         INC $26         ; Next: C3/F75C
         JSR C3F140      ; Switch names
         LDY #$0168      ; Frames: 360
         STY $20         ; Set fade delay
C3F75B:  RTS

; 8A: Fade all but Umaro's name
C3F75C:  LDY $20         ; Delay expired?
         BNE C3F75B      ; Exit if not
         LDA #$38        ; C3/F221
         STA $26         ; Next: Fd name
         LDA #$78        ; Fade delay
         STA $20         ; Set for name
         JSR C3F07F      ; Fade BGs
         JSR C3F1D8      ; Fade sprites
;        BRA C3F77F      ; Scroll table

; Set to scroll BG1 westward for 3 seconds
C3F77F:  LDY #$00B4      ; Frames: 180
C3EF27:  PHY             ; Save timer
         LDY #C3EF3C     ; C3/EF3C
         JSR qanim0      ; Queue anim fn
         REP #$20        ; 16-bit A
         PLA             ; Scroll timer
         STA $7E3349,X   ; Set mode timer
         SEP #$20        ; 8-bit A
         RTS

; Set to scroll BG1 westward for 20 seconds
C3F773:  LDY #$04B0      ; Frames: 1200
         BRA C3EF27      ; Queue panning

; Set to scroll BG1 westward for 5.2 seconds
C3F779:  LDY #$0138      ; Frames: 312
         BRA C3EF27      ; Queue panning

; Queue mosaic effect for book
C3F785:  LDA #$38        ; C3/F221
         STA $26         ; Next: Fd text
         LDY #C3F78C     ; C3/F78C
         JMP qanim0      ; Queue anim fn

; Handle mosaic effect for book
C3F78C:  BNE C3F79F      ; If mode 1

; Mode 0: Initialize mosaic
C3F794:  INC $3649,X     ; Mode +1
         STZ $33CA,X     ; Intensity: 0
         STZ $3349,X     ; Wait timer: 0

; Mode 1: Sustain mosaic
C3F79F:  LDA $3349,X     ; Delay expired?
         BEQ C3F7AB      ; Proceed if so
         DEC $3349,X     ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3F7AB:  LDA $33CA,X     ; Intensity
         ORA #$0F        ; Layers: All
         STA $B5         ; Set mosaic
         LDA $33CA,X     ; Intensity
         CLC             ; Prepare ADC
         ADC #$10        ; Intensity +1
         STA $33CA,X     ; Save changes
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set next wait
         SEC             ; Set to requeue
         RTS

; Create "as"
C3F7D1:  LDY #C3EDD4     ; C3/EDD4
         JSR qanim3      ; Queue anim fn
         REP #$20        ; 16-bit A
         LDA #$0258      ; Frames: 600
         STA $7E3349,X   ; Set hide delay
         SEP #$20        ; 8-bit A
         PEA $C079       ; Pos: 121, 192
         PEA $8E28       ; Anim ptr LBs
         LDA #$C2        ; Anim ptr HB
         PHA             ; Put on stack
         JMP C3F90X      ; Set sprite's

; Create Umaro's skull
C3F7FE:  LDA #$CF        ; Anim ptr HB
         LDY #$F51E      ; Anim ptr LBs
         LDX #$4FC4      ; Pos: 196, 79
         JSR C3F90C      ; Create sprite
         JMP C3F9A6      ; Follow BG1: Y

; Create four playing cards
C3F81D:  LDX #$5078      ; Pos: 120, 80
         LDY #$0020      ; H-Spd: +0.125 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3F8B4      ; Create card 1
         LDX #$C048      ; Pos: 72, 192
         LDY #$0040      ; H-Spd: +0.25 px
         PEA $0060       ; V-Spd: +0.375 px
         JSR C3F8B4      ; Create card 2
         LDX #$1098      ; Pos: 152, 16
         LDY #$FFE0      ; H-Spd: -0.125 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3F8B4      ; Create card 3
         LDX #$80D0      ; Pos: 208, 128
         LDY #$00A0      ; H-Spd: +0.625 px
         PEA $0080       ; V-Spd: +0.5 px
         JSR C3F8B4      ; Create card 4
         RTS             ; ^ Avoid JMP

; Create current playing card
C3F8B4:  PHY             ; Save H-Speed
         PHX             ; Save position
         SEP #$20        ; 8-bit A
         LDY #C3EDFB     ; C3/EDFB
         JSR qanim0      ; Queue anim fn
         LDA #$C2        ; Anim ptr HB
         LDY #$92F2      ; Anim ptr LBs
         JSR anm_st      ; Set card's
         PLY             ; Position
         JSR objpos      ; Set cards's
         REP #$20        ; 16-bit A
         PLA             ; H-Speed
         STA $7E34C9,X   ; Set card's
         PLY             ; Return adr
         PLA             ; V-Speed
         STA $7E3549,X   ; Set card's
         PHY             ; Repush adr
         SEP #$20        ; 8-bit A
         RTS

; Create face in Gau's diving helmet
C3F8CE:  LDA #$CF        ; Anim ptr HB
         LDY #$F5F7      ; Anim ptr LBs
         LDX #$5FCB      ; Pos: 203, 95
         JSR C3F90C      ; Create sprite
         BRA C3F9A6      ; Follow BG1: Y

; Create Shadow's apple
C3F8ED:  LDA #$C2        ; Anim ptr HB
         LDY #$948F      ; Anim ptr LBs
         LDX #$57C0      ; Pos: 192, 87
         JSR C3F90C      ; Create sprite
         BRA C3F9A6      ; Follow BG1: Y

; Create glowing eye in Gogo's helmet
C3F91E:  LDA #$CF        ; Anim ptr HB
         LDY #$F400      ; Anim ptr LBs
         LDX #$61C8      ; Pos: 200, 97
         JSR C3F90C      ; Create sprite
         BRA C3F9A6      ; Follow BG1: Y

; Create glint on Terra's pendant
C3F93D:  LDA #$CF        ; Anim ptr HB
         LDY #$F564      ; Anim ptr LBs
         LDX #$6080      ; Pos: 128, 96
;        BRA C3F90C      ; Create sprite

; Queue regular permanent sprite
C3F90C:  PHX             ; Save position
         PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         LDY #C3EDFB     ; C3/EDFB
         JSR qanim3      ; Queue OAM fn
C3F90X:  PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
C3F90Y:  PLY             ; Position
         JMP objpos      ; Set sprite's

; Set sprite to pan with BG1, define Y position
C3F9A2:  STA $7E344A,X   ; Set Y position
C3F9A6:  LDA #$01        ; Pans with BG1
         STA $7E364A,X   ; Set sprite flags
         RTS

; Create Mog's mini moogles and winding key
C3F95E:  LDA #$CF        ; Anim ptr HB
         LDY #$F4C5      ; Anim ptr LBs
         LDX #$6FE0      ; Pos: 224, 111
         JSR C3F90C      ; Create key
         JSR C3F9A6      ; Follow BG1: Y
         LDA #$BA        ; X: 186
         JSR C3F9AD      ; Queue moogle 1
         LDA #$C6        ; X: 198
         JSR C3F9AD      ; Queue moogle 2
         LDA #$D1        ; X: 209
         JSR C3F9AD      ; Queue moogle 3
         LDA #$DC        ; X: 220
;        BRA C3F9AD      ; Queue moogle 4

; Queue current mini moogle
C3F9AD:  PHA             ; Save X pos
         LDY #C3FA36     ; C3/FA36
         JSR qanim2      ; Queue anim fn
         PLA             ; X position
         STA $7E33CA,X   ; Set moogle's
         RTS

; Create Umaro's moogles
C3F9B6:  LDY #$01A4      ; Walk timer: 420
         LDX #$F42F      ; Bump anim ptr
         LDA #$3A        ; Base X: 58
         JSR C3F9A_      ; Create moogle 1
         LDY #$01B8      ; Walk timer: 440
         LDX #$F435      ; Bump anim ptr
         LDA #$2E        ; Base X: 46
         JSR C3F9A_      ; Create moogle 2
         LDY #$01CC      ; Walk timer: 460
         LDX #$F43B      ; Bump anim ptr
         LDA #$21        ; Base X: 33
         JSR C3F9A_      ; Create moogle 3
         LDY #$01E0      ; Walk timer: 480
         LDX #$F441      ; Bump anim ptr
         LDA #$14        ; Base X: 20
;        BRA C3F9A_      ; Create moogle 4

; Create mini moogle for Umaro's scene
C3F9A_:  PHX             ; Save pointer
         PHY             ; Save timer
         JSR C3F9AD      ; Queue OAM fn
         LDA #$05        ; Approach bones
         STA $7E3649,X   ; Set anim mode
         REP #$20        ; 16-bit A
         PLA             ; Walk timer
         STA $7E3349,X   ; Set moogle's
         PLA             ; Bump anim ptr
         STA $7E37C9,X   ; Set moogle's
         SEP #$20        ; 8-bit A
         RTS

; Initialize moogle's animation mode for Umaro
C3FA2F:  LDA #$05        ; Approach bones
         STA $7E3649,X   ; Set anim mode
         RTS

; Animate mini moogle
C3FA36:  TAX             ; Index mode
         JMP (C3FA3A,X)  ; Handle mode

; Jump table
C3FA3A:  dw C3FA4A       ; Initialize data
         dw C3FA6F       ; Spin around
         dw C3FA98       ; Face left
         dw C3FAB5       ; Jump down
         dw C3FAD1       ; Walk away from tree
         dw C3FAD6       ; Initialize data
         dw C3FAE3       ; Walk toward bones
         dw C3FB0A       ; Stop and fall down

; Mode 0: Initialize data
C3FA4A:  LDX $2D         ; Queue index
         INC $3649,X     ; Mode +1
         LDA #$64        ; Y: 100
         JSR C3F9A2      ; Set Y, pan flag
         LDA #$CF        ; Anim ptr HB
         LDY #$F408      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set spin timer
         JSR C31271      ; Set pose timer

; Mode 1: Spin around
C3FA6F:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3FA90      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY #$F42C      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$10        ; Frames: 16
         STA $3349,X     ; Set jump timer
         JSR C31271      ; Set pose timer
C3FA90:  JSR C3DF69      ; Mode timer -1
         BRA C3FB0A      ; Scroll & OAM

; Mode 2: Jump down
C3FA98:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3FAA7      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$3C        ; Frames: 60
         STA $3349,X     ; Set walk delay
C3FAA7:  JSR C3DF69      ; Mode timer -1
         JSR C3FB2A      ; Adjust Y-Pos
         INC $35C9,X     ; Y-Pos mod +1
         BRA C3FB0A      ; Scroll & OAM

; Mode 3: Face left
C3FAB5:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3FAC9      ; Branch if not
         JSR C3FB0F      ; Set to walk
C3FAC9:  JSR C3DF69      ; Mode timer -1
;        BRA C3FB0A      ; Scroll & OAM

; Mode 4: Walk away from tree
C3FAD1:  BRA C3FB0A      ; Scroll & OAM

; Mode 5: Initialize data
C3FAD6:  LDX $2D         ; Queue index
         JSR C3FB0F      ; Set to walk
         LDA #$70        ; Y: 112
         JSR C3F9A2      ; Set Y, pan flag

; Mode 6: Walk toward bones
C3FAE3:  LDX $2D         ; Queue index
         LDY $3349,X     ; Mode expired?
         BNE C3FB02      ; Branch if not
         INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY $37C9,X     ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
;        REP #$20        ; 16-bit A
         STZ $34C9,X     ; H-Speed: 0
         JSR C31271      ; Set pose timer
C3FB02:  JSR C3DF69      ; Mode timer -1
;        BRA C3FB0A      ; Scroll & OAM

; Mode 7: Stop and fall down
C3FB0A:  JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set mini moogle to walk eastward
C3FB0F:  INC $3649,X     ; Mode +1
         LDA #$CF        ; Anim ptr HB
         LDY #$F423      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$0040      ; H-Spd: +0.25 px
         STA $34C9,X     ; Set sprite's
         JMP C31271      ; Set pose timer

; Adjust jumping mini moogle's Y position
C3FB2A:  LDA $35C9,X     ; Modifier index
;        AND #$0F        ; ...
         TAX             ; Index it
         LDA $CFF50E,X   ; Y modifier
         LDX $2D         ; Queue index
         CLC             ; Prepare ADC
         ADC $344A,X     ; Add sprite's Y
         STA $344A,X     ; Set sprite's Y
         RTS

; Queue brush or katana glint
C3FB79:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         PHB             ; Save DB
         LDY #C3FC4E     ; C3/FC4E
         JSR qanim2      ; Queue anim fn
         PLB             ; Restore DB
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set glint's

; Create a series of glints on Relm's brush
C3FB82:  BNE C3FBA1      ; If mode 1

; Mode 0: Initialize wave
C3FB8A:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$E4        ; X: 228
         STA $C7         ; Set base X
         LDA #$03        ; Glints: 3
         STA $C9         ; Set counter

; Mode 1: Create wave
C3FBA1:  LDA $C9         ; Glints left
         BEQ C3FC4C      ; Dequeue if 0
         LDY $3349,X     ; Delay expired?
         BNE C3FC47      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         LDA #$CF        ; Anim ptr HB
         LDY #$F564      ; Anim ptr LBs
         JSR C3FB79      ; Queue glint
         LDA #$68        ; Y: 104
         BRA glints      ; X = $C7

; Create a series of glints on Cyan's katana
C3FBE8:  BNE C3FC07      ; If mode 1

; Mode 0: Initialize wave
C3FBF0:  INC $3649,X     ; Mode +1
         REP #$20        ; 16-bit A
         LDA #$0168      ; Frames: 360
         STA $3349,X     ; Set wave delay
         SEP #$20        ; 8-bit A
         LDA #$C8        ; X: 200
         STA $C7         ; Set base X
         LDA #$04        ; Glints: 4
         STA $C9         ; Set counter

; Mode 1: Create wave
C3FC07:  LDA $C9         ; Glints left
         BEQ C3FC4C      ; Dequeue if 0
         LDY $3349,X     ; Delay expired?
         BNE C3FC47      ; Branch if not
         LDA #$08        ; Frames: 8
         STA $3349,X     ; Set next delay
         LDA #$CF        ; Anim ptr HB
         LDY #$F5AA      ; Anim ptr LBs
         JSR C3FB79      ; Queue glint
         LDA #$60        ; Y: 96
glints:  STA $344A,X     ; Set glint's
         LDA $C7         ; Base X
         STA $33CA,X     ; Set glint's
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         DEC A           ; Base X -1
         STA $C7         ; Save changes
         DEC $C9         ; Glints left -1
C3FC47:  JSR C3DF69      ; Delay -1
         SEC             ; Set to requeue
         RTS             ; Exit
C3FC4C:  CLC             ; Set to dequeue
         RTS

; Animate glint on brush or katana
C3FC4E:  BNE C3FC63      ; If mode 1

; Mode 0: Initialize sprite
C3FC56:  JSR C31271      ; Set pose timer
         INC $3649,X     ; Mode +1
         JSR C3F9A6      ; Follow BG1: Y

; Mode 1: Sustain sprite
C3FC63:  LDA $36CA,X     ; Pose timer
         CMP #$FE        ; Set as endless?
         BEQ C3FC71      ; Delete if so
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS             ; Exit
C3FC71:  CLC             ; Set to dequeue
         RTS

; Animate double-headed coin
C3FC73:  BNE C3FCA7      ; If mode 1

; Mode 0: Initialize sprite
C3FC7B:  INC $3649,X     ; Mode +1
         LDA #$D8        ; Anim ptr HB
         LDY #$ED1D      ; Anim ptr LBs
         JSR anm_st      ; Set sprite's
         LDA #$C8        ; Frames: 200
         STA $3349,X     ; Set roll timer
         LDY #$6410      ; Pos: 16, 100
         JSR objpos      ; Set sprite's
         REP #$20        ; 16-bit A
         LDA #$0080      ; H-Spd: +0.5 px
         STA $34C9,X     ; Set sprite's
         JSR C31271      ; Set pose timer

; Mode 1: Sustain sprite
C3FCA7:  LDA $3349,X     ; Stop rolling?
         BNE C3FCB1      ; Branch if not
         STZ $34C9,X     ; H-Speed: 0
C3FCB1:  DEC $3349,X     ; Roll timer -1
         JSR C3EE10      ; Scroll & OAM
         SEC             ; Set to requeue
         RTS

; Set to animate Strago's book
C3FCB9:  LDA #$C2        ; Anim ptr HB
         LDY #$8B62      ; Anim ptr LBs
         BRA C3FCF8      ; Queue anim fn

; Set to animate first book
C3FCCE:  LDA #$C2        ; Anim ptr HB
         LDY #$8B53      ; Anim ptr LBs
         BRA C3FCF8      ; Queue anim fn

; Set to animate last book
C3FCE3:  LDA #$C2        ; Anim ptr HB
         LDY #$8B35      ; Anim ptr LBs

; Set to animate book
C3FCF8:  PHY             ; Save ptr LBs
         PHA             ; Save ptr HB
         STZ $99         ; Last page: N
         LDY #C3FD3E     ; C3/FD3E
         JSR qanim1      ; Queue anim fn
         PLA             ; Anim ptr HB
         PLY             ; Anim ptr LBs
         JMP anm_st      ; Set book's

; Integrate decompressed tilemap segment, adjust attributes
C3FD07:  STX $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         STY $EB         ; Set dst LBs
         LDA #$7E        ; Bank: 7E
         STA $ED         ; Set dst HB
         LDX $00         ; Rows done: 0
         REP #$20        ; 16-bit A
C3FD17:  TDC             ; Clear A
         TAY             ; Index: 0
C3FD19:  LDA [$E7],Y     ; Attributes
;        CLC             ; Prepare ADC
;        ADC $60         ; Always 0...
         STA [$EB],Y     ; Put in map
         INY             ; Index +1
         INY             ; Index +1
         CPY $E0         ; End of row?
         BNE C3FD19      ; Loop if not
         LDA $E7         ; Source LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $E7         ; Save changes
         LDA $EB         ; Dest LBs
         CLC             ; Prepare ADC
         ADC #$0040      ; Go 1 row down
         STA $EB         ; Save changes
         INX             ; Rows done +1
         CPX $E2         ; More left?
         BNE C3FD17      ; Loop if so
         SEP #$20        ; 8-bit A
         RTS

; Animate book
C3FD3E:  CMP #$02        ; Mode 1?
         BEQ C3FD52      ; Branch if so
         BCS C3FD56      ; If mode 2

; Mode 0: Initialize timer
C3FD48:  JSR C3127_      ; Set pose timer
         INC $3649,X     ; Mode +1
         SEC             ; Set to requeue
         RTS

; Mode 1: Check if last page
C3FD52:  LDA $99         ; Last page?
         BEQ C3FD56      ; Branch if not

; Fork: Set to stop animation
C3FD93:  INC $3649,X     ; Mode +1
         LDA #$C2        ; Anim ptr HB
         LDY #$8B44      ; Anim ptr LBs
         JSR anm_st      ; Set book's
         JSR C31271      ; Set pose timer

; Mode 2: Update tilemap
C3FD56:  JSR C31292      ; Pose timer -1
         LDX $2D         ; Queue index
         LDA $35CA,X     ; Anim ptr HB
         STA $E9         ; Set src HB
         TDC             ; Clear A
         LDA $36C9,X     ; Pose index
         TAY             ; Index it
         REP #$20        ; 16-bit A
         LDA [$EB],Y     ; Pose info loc
         STA $E7         ; Set src LBs
         LDA [$E7]       ; Column count
         STA $E0         ; Set width
         LDY #$0002      ; Src index
         LDA [$E7],Y     ; Row count
         STA $E2         ; Set height
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Source LBs
         TAX             ; Put in X
         INY             ; Src index +1
         INY             ; Src index +1
         LDA [$E7],Y     ; Dest LBs
         TAY             ; Put in Y
         SEP #$20        ; 8-bit A
         JSR C3FD07      ; Replace tiles
         SEC             ; Set to requeue
         RTS

; Unpack and upload large font graphics for actor scene
C3FDAE:  LDY #$B500      ; Source LBs
         LDA #$CE        ; Source HB
         JSR C3ECB1      ; Unpack GFX
         JSR C3E47D      ; Src: 7E/C000
         LDX #$0900      ; Bytes: 2304
         LDY #$7000      ; VRAM pointer
         JMP C3ECD6      ; Upload GFX

; Unpack and upload BG graphics and tilemaps for actor scene
C3FDCA:  LDY #$BB08      ; Source LBs
         LDA #$CE        ; Source HB
         JSR C3ECB1      ; Unpack data

; Fork: Copy table's map to BG1 tilemap A
C3FDD2:  LDY #$3849      ; Tilemap ptr
         JSR C3FE4A      ; Move data

; Fork: Copy table's map to BG1 tilemap B
C3FDDE:  LDY #$4049      ; Tilemap ptr
         JSR C3FE4A      ; Move data

; Fork: Upload tall items and table side graphics
C3FDEA:  JSR C3E47D      ; Src: 7E/C000
         LDX #$1F60      ; Bytes: 8032
         LDY #$3000      ; VRAM pointer
         JSR C3ED0_      ; Upload data

; Fork: Upload large items, tabletop, and overlay graphics
C3FE02:  LDY #$DF60      ; 7E/DF60
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0B40      ; Bytes: 2880
         LDY #$4000      ; VRAM pointer
         JSR C3ED0_      ; Upload data

; Fork: Upload book graphics
C3FE1A:  LDY #$EAA0      ; 7E/EAA0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         LDX #$0E00      ; Bytes: 3584
         LDY #$5000      ; VRAM pointer
         JSR C3ED0_      ; Upload data

; Fork: Upload transparent overlay tilemap (BG2)
C3FE32:  LDY #$0448      ; 7F/0448
         STY $E7         ; Set src LBs
         LDA #$7F        ; Bank: 7F
         STA $E9         ; Set src HB
         LDX #$0780      ; Bytes: 1920
         LDY #$1000      ; VRAM pointer
         JMP C3ED0_      ; Upload data

; Relocate decompressed tilemap for table
C3FE4A:  STY $EB         ; Set dst LBs
         LDY #$F8A0      ; 7E/F8A0
         STY $E7         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $E9         ; Set src HB
         STA $ED         ; Set dst HB
         LDY #$0780      ; Bytes: 1920
         JMP C3E653      ; Move data

; Set to upload BG1 and BG3 tilemaps for actor scene
C3FE5B:  LDY #$1800      ; $1800
         STY $1B         ; Set VRAM ptr
         LDY #$7849      ; 7E/7849
         STY $1D         ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $1F         ; Set src HB
         LDY #$0800      ; Bytes: 2048
         STY $19         ; Set data size
         JMP C30F54      ; Handle BG1

; Unpack and upload apple and shuriken graphics
C3FE82:  LDY #$EF77      ; Source LBs
         LDA #$CE        ; Source HB
         JSR C3ECB1      ; Unpack GFX
         JSR C3E47D      ; Src: 7E/C000
         LDX #$0380      ; Bytes: 896
         LDY #$6000      ; VRAM pointer
         JMP C3ED0_      ; Upload GFX

; Draw Cyan's katana; unpack and upload glint
C3FEA2:  JSR C3FF70      ; Handle glint
         LDY #$0026      ; Tiles: 19
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$03E0      ; Src: 7F/03E0
         LDY #$3BA1      ; Dst: 7E/3BA1
         JMP C3FD07      ; Draw katana

; Unpack and upload coin graphics
C3FEB8:  JSR C3FEC1      ; Unpack data
         LDY #$6000      ; VRAM pointer
         JMP C3ED0_      ; Upload data

; Unpack skull and coin graphics; prepare upload
C3FEC1:  LDY #$9D4B      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3ECB1      ; Unpack GFX
         LDX #$0800      ; Bytes: 896
         JMP C3E47D      ; Src: 7E/C000

; Draw Mog's tree; unpack and upload sprites
C3FEDC:  JSR C3FF70      ; Do sprites
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0008      ; Tiles: 8
         STY $E2         ; Set height
         LDX #$0020      ; Src: 7F/0020
C3FEEC:  LDY #$3A77      ; Dst: 7E/3A77
         JMP C3FD07      ; Draw tree

; Draw Gogo's helmet; unpack and upload glint
C3FEF2:  JSR C3FF70      ; Handle glint
         LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0009      ; Tiles: 9
         STY $E2         ; Set height
         LDX #$002E      ; Src: 7F/002E
         LDY #$3A2D      ; Dst: 7E/3A2D
         JMP C3FD07      ; Draw helmet

; Draw Gau's diving helmet; unpack and upload face
C3FF08:  JSR C3FF90      ; Handle face
         LDY #$000C      ; Tiles: 6
         STY $E0         ; Set width
         LDY #$0007      ; Tiles: 7
         STY $E2         ; Set height
         LDX #$004A      ; Src: 7F/004A
         LDY #$3AB7      ; Dst: 7E/3AB7
         JMP C3FD07      ; Draw helmet

; Draw Terra's cocktail glasses; unpack and upload glint
C3FF1E:  JSR C3FF70      ; Handle glint
         LDY #$000E      ; Tiles: 7
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0220      ; Src: 7F/0220
         LDY #$3B35      ; Dst: 7E/3B35
         JMP C3FD07      ; Draw glasses

; Draw Locke and Celes's bouquet
C3FF34:  LDY #$0018      ; Tiles: 12
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0274      ; Src: 7F/0274
         LDY #$3B69      ; Dst: 7E/3B69
         JMP C3FD07      ; Replace tiles

; Draw Relm's brush; unpack and upload glint
C3FF47:  JSR C3FF70      ; Handle glint
         LDY #$0014      ; Tiles: 10
         STY $E0         ; Set width
         LDY #$0002      ; Tiles: 2
         STY $E2         ; Set height
         LDX #$0360      ; Src: 7F/0360
         LDY #$3BF3      ; Dst: 7E/3BF3
         JMP C3FD07      ; Draw brush

; Draw an open book
C3FF5D:  LDY #$001C      ; Tiles: 14
         STY $E0         ; Set width
         LDY #$0006      ; Tiles: 6
         STY $E2         ; Set height
         LDX #$0BC8      ; Src: 7F/0BC8
         LDY #$3AD9      ; Dst: 7E/3AD9
         JMP C3FD07      ; Replace tiles

; Unpack and upload card, glint, moogle, and winding key graphics
C3FF70:  LDY #$F1FB      ; Source LBs
         LDA #$CE        ; Source HB
         JSR C3ECB1      ; Unpack GFX
         JSR C3E47D      ; Src: 7E/C000
         LDX #$0DF0      ; Bytes: 3568
         LDY #$6000      ; VRAM pointer
         JMP C3ED0_      ; Upload GFX

; Unpack and upload face graphics for Gau's scene
C3FF90:  LDY #$A4E5      ; Source LBs
         LDA #$D9        ; Source HB
         JSR C3ECB1      ; Unpack GFX
         JSR C3E47D      ; Src: 7E/C000
         LDX #$00C0      ; Bytes: 192
         LDY #$6000      ; VRAM pointer
         JMP C3ECD6      ; Upload GFX

; Draw Umaro's bones; unpack and upload sprites
C3FFAC:  JSR C3FF70      ; Handle moogles
         JSR C3FEC1      ; Unpack skull
         LDY #$6800      ; VRAM pointer
         JSR C3ED0_      ; Upload skull
         LDY #$000A      ; Tiles: 5
         STY $E0         ; Set width
         LDY #$0005      ; Tiles: 5
         STY $E2         ; Set height
         LDX #$0056      ; Src: 7F/0056
         LDY #$3B37      ; Dst: 7E/3B37
         JMP C3FD07      ; Draw bones

; =========================[ Navigation parameters ]===========================

; Navigation data for Save menu
C3161C:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $03          ; 3 rows

; Navigation data for Load menu
C31630:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for save file confirmation
C3164C:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Navigation data for main menu
C33020:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for non-shifted Status menu
C337D6:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Config page 1
C33936:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0A          ; 10 rows

; Navigation data for Config page 2
C3395E:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $06          ; 6 rows

; Navigation data for Cmd.Set menu's actor list
C346A6:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $05          ; 5 rows

; Navigation data for Cmd.Set menu's command list
C3472B:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Controller menu
C34A1B:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for Button Settings menu
C34AE3:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for Skills menu
C35232:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $01          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for Magic menu
C3526C:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $09          ; 9 rows

; Navigation data for SwdTech, Blitz, and Dance menus
C352B8:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $04          ; 4 rows

; Navigation data for Lore and Espers menus
C352DC:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $09          ; 9 rows

; Navigation data for Rage menu
C35314:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $09          ; 9 rows

; Navigation data for esper data menu
C35FE1:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $07          ; 7 rows

; Navigation data for shifted Status menu
C36A5B:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $10          ; 16 rows

; Navigation data for actor naming menu
C36D2F:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $0A          ; 10 columns
         db $0A          ; 10 rows

; Navigation data for non-party area of Lineup menu
C37C52:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $08          ; 8 columns
         db $02          ; 2 rows

; Navigation data for single-party area of Lineup menu
C37C77:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $02          ; 2 rows

; Navigation data for two-party area of Lineup menu
C37C84:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $02          ; 2 rows

; Navigation data for three-party area of Lineup menu
C37C99:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $06          ; 6 columns
         db $02          ; 2 rows

; Navigation data for Item, Colosseum, and Sell menus
C384B2:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $0A          ; 10 rows

; Navigation data for rare item menu
C384EE:  db $00          ; Wraps on all sides
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $0A          ; 10 rows

; Navigation data for Item menu options
C38547:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Navigation data for Equip menu options
C395D4:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Navigation data for Equip menu slot selection
C395F0:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Navigation data for equipment list
C3961B:  db $81          ; Never wraps
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $09          ; 9 rows

; Navigation data for Relic menu options
C39641:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $02          ; 2 columns
         db $01          ; 1 row

; Navigation data for relic slot selection
C39659:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $02          ; 2 rows

; Navigation data for final battle lineup
C3B5D3:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $0E          ; 14 rows

; Navigation data for Colosseum matchup menu
C3BC9F:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $04          ; 4 columns
         db $01          ; 1 row

; Navigation data for name area in SwdTech naming menu
C3C08E:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $06          ; 6 columns
         db $01          ; 1 row

; Navigation data for SwdTech naming menu options
C3C0AE:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $07          ; 7 columns
         db $08          ; 8 rows

; Navigation data for main shop menu
C3C7EC:  db $01          ; Wraps horizontally
         db $00          ; Initial column
         db $00          ; Initial row
         db $03          ; 3 columns
         db $01          ; 1 row

; Navigation data for Buy menu
C3C806:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $08          ; 8 rows

; Navigation data for portrait selection
C330DD:  db $80          ; Wraps vertically
         db $00          ; Initial column
         db $00          ; Initial row
         db $01          ; 1 column
         db $04          ; 4 rows

; Cursor positions for portrait selection
C330E2:  dw $2808        ; Member 1
         dw $5808        ; Member 2
         dw $8808        ; Member 3
         dw $B808        ; Member 4

; Cursor positions above must follow nav table.


; ============================[ Cursor positions ]=============================

; Cursor positions for Save and Load menus
C31635:  dw $1C08        ; New Game
C31637:  dw $3C08        ; Save file 1
         dw $7408        ; Save file 2
         dw $AC08        ; Save file 3

; Cursor positions for save file confirmation
C31651:  dw $44BF        ; Yes
         dw $54BF        ; No

; Cursor positions for main menu
C33025:  dw $12B7        ; Item
         dw $21B7        ; Skills
         dw $30B7        ; Equip
         dw $3FB7        ; Relic
         dw $4EB7        ; Status
         dw $5DB7        ; Config
         dw $6CB7        ; Save

; Cursor positions for non-shifted Status menu
C337DB:  dw $5990        ; Command 1
         dw $6590        ; Command 2
         dw $7190        ; Command 3
         dw $7D90        ; Command 4

; Cursor positions for Config page 1
C3393B:  dw $2960        ; Bat.Mode
         dw $3960        ; Bat.Speed
         dw $4960        ; Msg.Speed
         dw $5960        ; Cmd.Set
         dw $6960        ; Gauge
         dw $7960        ; Sound
         dw $8960        ; Cursor
         dw $9960        ; Reequip
         dw $A960        ; Button
         dw $B960        ; Controller

; Cursor positions for Config page 2
C33963:  dw $2960        ; Mag.Order
         dw $6960        ; Window
         dw $7960        ; Color
         dw $9960        ; R
         dw $A960        ; G
         dw $B960        ; B

; Cursor positions for Cmd.Set menu's actor list
C346AB:  dw $2008        ; Member 1
         dw $5008        ; Member 2
         dw $8008        ; Member 3
         dw $B008        ; Member 4
         dw $0C08        ; Arrange

; Cursor positions for member 1 in Cmd.Set menu
C34730:  dw $2080        ; Command 1
         dw $2C58        ; Command 2
         dw $2CA8        ; Command 3
         dw $3880        ; Command 4

; Cursor positions for member 2 in Cmd.Set menu
C34738:  dw $5080        ; Command 1
         dw $5C58        ; Command 2
         dw $5CA8        ; Command 3
         dw $6880        ; Command 4

; Cursor positions for member 3 in Cmd.Set menu
C34740:  dw $8080        ; Command 1
         dw $8C58        ; Command 2
         dw $8CA8        ; Command 3
         dw $9880        ; Command 4

; Cursor positions for member 4 in Cmd.Set menu
C34748:  dw $B080        ; Command 1
         dw $BC58        ; Command 2
         dw $BCA8        ; Command 3
         dw $C880        ; Command 4

; Cursor positions for Controller menu
C34A20:  dw $7B50        ; Member 1
         dw $8B50        ; Member 2
         dw $9B50        ; Member 3
         dw $AB50        ; Member 4

; Cursor positions for Button Settings menu
C34AE8:  dw $2310        ; A
         dw $3B10        ; B
         dw $5310        ; X
         dw $6B10        ; Y
         dw $8310        ; L
         dw $9B10        ; R
         dw $B310        ; Select

; Cursor positions for Skills menu
C35237:  dw $1400        ; Espers
         dw $2400        ; Magic
         dw $4400        ; SwdTech
         dw $5400        ; Blitz
         dw $6400        ; Lore
         dw $7400        ; Rage
         dw $8400        ; Dance

; Cursor positions for Magic menu
C35271:  dw $6808        ; Spell 1
         dw $6850        ; Spell 2
         dw $6898        ; Spell 3
         dw $7408        ; Spell 4
         dw $7450        ; Spell 5
         dw $7498        ; Spell 6
         dw $8008        ; Spell 7
         dw $8050        ; Spell 8
         dw $8098        ; Spell 9
         dw $8C08        ; Spell 10
         dw $8C50        ; Spell 11
         dw $8C98        ; Spell 12
         dw $9808        ; Spell 13
         dw $9850        ; Spell 14
         dw $9898        ; Spell 15
         dw $A408        ; Spell 16
         dw $A450        ; Spell 17
         dw $A498        ; Spell 18
         dw $B008        ; Spell 19
         dw $B050        ; Spell 20
         dw $B098        ; Spell 21
         dw $BC08        ; Spell 22
         dw $BC50        ; Spell 23
         dw $BC98        ; Spell 24
         dw $C808        ; Spell 25
         dw $C850        ; Spell 26
         dw $C898        ; Spell 27

; Cursor positions for SwdTech, Blitz, and Dance menus
C352BD:  dw $7418        ; Skill 1
         dw $7488        ; Skill 2
         dw $8C18        ; Skill 3
         dw $8C88        ; Skill 4
         dw $A418        ; Skill 5
         dw $A488        ; Skill 6
         dw $BC18        ; Skill 7
         dw $BC88        ; Skill 8

; Cursor positions for Lore and Espers menus
C352E1:  dw $6808        ; Skill 1
         dw $6878        ; Skill 2
         dw $7408        ; Skill 3
         dw $7478        ; Skill 4
         dw $8008        ; Skill 5
         dw $8078        ; Skill 6
         dw $8C08        ; Skill 7
         dw $8C78        ; Skill 8
         dw $9808        ; Skill 9
         dw $9878        ; Skill 10
         dw $A408        ; Skill 11
         dw $A478        ; Skill 12
         dw $B008        ; Skill 13
         dw $B078        ; Skill 14
         dw $BC08        ; Skill 15
         dw $BC78        ; Skill 16
         dw $C808        ; Skill 17
         dw $C878        ; Skill 18

; Cursor positions for Rage menu
C35319:  dw $6818        ; Rage 1
         dw $6888        ; Rage 2
         dw $7418        ; Rage 3
         dw $7488        ; Rage 4
         dw $8018        ; Rage 5
         dw $8088        ; Rage 6
         dw $8C18        ; Rage 7
         dw $8C88        ; Rage 8
         dw $9818        ; Rage 9
         dw $9888        ; Rage 10
         dw $A418        ; Rage 11
         dw $A488        ; Rage 12
         dw $B018        ; Rage 13
         dw $B088        ; Rage 14
         dw $BC18        ; Rage 15
         dw $BC88        ; Rage 16
         dw $C818        ; Rage 17
         dw $C888        ; Rage 18

; Cursor positions for esper data menu
C35FE6:  dw $7010        ; Esper
         dw $7C18        ; Spell A
         dw $8818        ; Spell B
         dw $9418        ; Spell C
         dw $A018        ; Spell D
         dw $AC18        ; Spell E
         dw $B818        ; Bonus

; Cursor positions for shifted Status menu
C36A60:  dw $10F8        ; Empty
         dw $1CF8        ; Command 1
         dw $28F8        ; Command 2
         dw $34F8        ; Command 3
         dw $40F8        ; Command 4
         dw $4CF8        ; Command 5
         dw $58F8        ; Command 6
         dw $64F8        ; Command 7
         dw $70F8        ; Command 8
         dw $7CF8        ; Command 9
         dw $88F8        ; Command 10
         dw $94F8        ; Command 11
         dw $A0F8        ; Command 12
         dw $ACF8        ; Command 13
         dw $B8F8        ; Command 14
;        dw $C4F8        ; Command 15 (unused)

; Cursor positions for actor naming menu
C36D34:  dw $3838        ; Row 1, column 1
         dw $3848        ; Row 1, column 2
         dw $3858        ; Row 1, column 3
         dw $3868        ; Row 1, column 4
         dw $3878        ; Row 1, column 5
         dw $3890        ; Row 1, column 6
         dw $38A0        ; Row 1, column 7
         dw $38B0        ; Row 1, column 8
         dw $38C0        ; Row 1, column 9
         dw $38D0        ; Row 1, column 10
         dw $4838        ; Row 2, column 1
         dw $4848        ; Row 2, column 2
         dw $4858        ; Row 2, column 3
         dw $4868        ; Row 2, column 4
         dw $4878        ; Row 2, column 5
         dw $4890        ; Row 2, column 6
         dw $48A0        ; Row 2, column 7
         dw $48B0        ; Row 2, column 8
         dw $48C0        ; Row 2, column 9
         dw $48D0        ; Row 2, column 10
         dw $5838        ; Row 3, column 1
         dw $5848        ; Row 3, column 2
         dw $5858        ; Row 3, column 3
         dw $5868        ; Row 3, column 4
         dw $5878        ; Row 3, column 5
         dw $5890        ; Row 3, column 6
         dw $58A0        ; Row 3, column 7
         dw $58B0        ; Row 3, column 8
         dw $58C0        ; Row 3, column 9
         dw $58D0        ; Row 3, column 10
         dw $6838        ; Row 4, column 1
         dw $6848        ; Row 4, column 2
         dw $6858        ; Row 4, column 3
         dw $6868        ; Row 4, column 4
         dw $6878        ; Row 4, column 5
         dw $6890        ; Row 4, column 6
         dw $68A0        ; Row 4, column 7
         dw $68B0        ; Row 4, column 8
         dw $68C0        ; Row 4, column 9
         dw $68D0        ; Row 4, column 10
         dw $7838        ; Row 5, column 1
         dw $7848        ; Row 5, column 2
         dw $7858        ; Row 5, column 3
         dw $7868        ; Row 5, column 4
         dw $7878        ; Row 5, column 5
         dw $7890        ; Row 5, column 6
         dw $78A0        ; Row 5, column 7
         dw $78B0        ; Row 5, column 8
         dw $78C0        ; Row 5, column 9
         dw $78D0        ; Row 5, column 10
         dw $8838        ; Row 6, column 1
         dw $8848        ; Row 6, column 2
         dw $8858        ; Row 6, column 3
         dw $8868        ; Row 6, column 4
         dw $8878        ; Row 6, column 5
         dw $8890        ; Row 6, column 6
         dw $88A0        ; Row 6, column 7
         dw $88B0        ; Row 6, column 8
         dw $88C0        ; Row 6, column 9
         dw $88D0        ; Row 6, column 10
         dw $9838        ; Row 7, column 1
         dw $9848        ; Row 7, column 2
         dw $9858        ; Row 7, column 3
         dw $9868        ; Row 7, column 4
         dw $9878        ; Row 7, column 5
         dw $9890        ; Row 7, column 6
         dw $98A0        ; Row 7, column 7
         dw $98B0        ; Row 7, column 8
         dw $98C0        ; Row 7, column 9
         dw $98D0        ; Row 7, column 10
         dw $A838        ; Row 8, column 1
         dw $A848        ; Row 8, column 2
         dw $A858        ; Row 8, column 3
         dw $A868        ; Row 8, column 4
         dw $A878        ; Row 8, column 5
         dw $A890        ; Row 8, column 6
         dw $A8A0        ; Row 8, column 7
         dw $A8B0        ; Row 8, column 8
         dw $A8C0        ; Row 8, column 9
         dw $A8D0        ; Row 8, column 10
         dw $B838        ; Row 9, column 1
         dw $B848        ; Row 9, column 2
         dw $B858        ; Row 9, column 3
         dw $B868        ; Row 9, column 4
         dw $B878        ; Row 9, column 5
         dw $B890        ; Row 9, column 6
         dw $B8A0        ; Row 9, column 7
         dw $B8B0        ; Row 9, column 8
         dw $B8C0        ; Row 9, column 9
         dw $B8D0        ; Row 9, column 10
         dw $C838        ; Row 10, column 1
         dw $C848        ; Row 10, column 2
         dw $C858        ; Row 10, column 3
         dw $C868        ; Row 10, column 4
         dw $C878        ; Row 10, column 5
         dw $C890        ; Row 10, column 6
         dw $C8A0        ; Row 10, column 7
         dw $C8B0        ; Row 10, column 8
         dw $C8C0        ; Row 10, column 9
         dw $C8D0        ; Row 10, column 10

; Cursor positions for non-party area of Lineup menu
C37C57:  dw $6408        ; Slot 1
         dw $6424        ; Slot 2
         dw $6440        ; Slot 3
         dw $645C        ; Slot 4
         dw $6478        ; Slot 5
         dw $6494        ; Slot 6
         dw $64B0        ; Slot 7
         dw $64CC        ; Slot 8
         dw $8008        ; Slot 9
         dw $8024        ; Slot 10
         dw $8040        ; Slot 11
         dw $805C        ; Slot 12
         dw $8078        ; Slot 13
         dw $8094        ; Slot 14
         dw $80B0        ; Slot 15
         dw $80CC        ; Slot 16

; Cursor positions for single-party area of Lineup menu
C37C7C:  dw $A408        ; NW
         dw $A428        ; NE
         dw $C008        ; SW
         dw $C028        ; SE

; Cursor positions for two-party area of Lineup menu
C37C89:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE

; Cursor positions for three-party area of Lineup menu
C37C9E:  dw $A408        ; Party 1, NW
         dw $A428        ; Party 1, NE
         dw $A458        ; Party 2, NW
         dw $A478        ; Party 2, NE
         dw $A4A8        ; Party 3, NW
         dw $A4C8        ; Party 3, NE
         dw $C008        ; Party 1, SW
         dw $C028        ; Party 1, SE
         dw $C058        ; Party 2, SW
         dw $C078        ; Party 2, SE
         dw $C0A8        ; Party 3, SW
         dw $C0C8        ; Party 3, SE

; Cursor positions for Item, Colosseum, and Sell menus
C384B7:  dw $5C08        ; Item 1
         dw $5C78        ; Item 2
         dw $6808        ; Item 3
         dw $6878        ; Item 4
         dw $7408        ; Item 5
         dw $7478        ; Item 6
         dw $8008        ; Item 7
         dw $8078        ; Item 8
         dw $8C08        ; Item 9
         dw $8C78        ; Item 10
         dw $9808        ; Item 11
         dw $9878        ; Item 12
         dw $A408        ; Item 13
         dw $A478        ; Item 14
         dw $B008        ; Item 15
         dw $B078        ; Item 16
         dw $BC08        ; Item 17
         dw $BC78        ; Item 18
         dw $C808        ; Item 19
         dw $C878        ; Item 20

; Cursor positions for rare item menu
C384F3:  dw $5C08        ; Item 1
         dw $5C50        ; Item 2
         dw $5C98        ; Item 3
         dw $6808        ; Item 4
         dw $6850        ; Item 5
         dw $6898        ; Item 6
         dw $7408        ; Item 7
         dw $7450        ; Item 8
         dw $7498        ; Item 9
         dw $8008        ; Item 10
         dw $8050        ; Item 11
         dw $8098        ; Item 12
         dw $8C08        ; Item 13
         dw $8C50        ; Item 14
         dw $8C98        ; Item 15
         dw $9808        ; Item 16
         dw $9850        ; Item 17
         dw $9898        ; Item 18
         dw $A408        ; Item 19
         dw $A450        ; Item 20
         dw $A498        ; Item 21
         dw $B008        ; Item 22
         dw $B050        ; Item 23
         dw $B098        ; Item 24
         dw $BC08        ; Item 25
         dw $BC50        ; Item 26
         dw $BC98        ; Item 27
         dw $C808        ; Item 28
         dw $C850        ; Item 29
         dw $C898        ; Item 30

; Cursor positions for Item menu options
C3854C:  dw $1640        ; USE
         dw $1670        ; ARRANGE
         dw $16A8        ; RARE

; Cursor positions for Equip menu options
C395D9:  dw $1010        ; EQUIP
         dw $1038        ; OPTIMUM
         dw $1070        ; RMOVE
         dw $10A0        ; EMPTY

; Cursor positions for Equip menu slot selection
C395F5:  dw $2C38        ; R-Hand
         dw $3838        ; L-Hand
         dw $4438        ; Head
         dw $5038        ; Body

; Cursor positions for equipment list
C39620:  dw $6800        ; Item 1
         dw $7400        ; Item 2
         dw $8000        ; Item 3
         dw $8C00        ; Item 4
         dw $9800        ; Item 5
         dw $A400        ; Item 6
         dw $B000        ; Item 7
         dw $BC00        ; Item 8
         dw $C800        ; Item 9

; Cursor positions for Relic menu options
C39646:  dw $1010        ; Equip
         dw $1038        ; Remove

; Cursor positions for relic slots
C3965E:  dw $4438        ; Relic 1
         dw $5038        ; Relic 2

; Cursor positions for final battle lineup
C3B5D8:  dw $2010        ; Reset
         dw $2C20        ; Actor 1
         dw $3820        ; Actor 2
         dw $4420        ; Actor 3
         dw $5020        ; Actor 4
         dw $5C20        ; Actor 5
         dw $6820        ; Actor 6
         dw $7420        ; Actor 7
         dw $8020        ; Actor 8
         dw $8C20        ; Actor 9
         dw $9820        ; Actor 10
         dw $A420        ; Actor 11
         dw $B020        ; Actor 12
         dw $BC10        ; End

; Cursor positions for Colosseum matchup menu
C3BCA4:  dw $B010        ; Member 1
         dw $B048        ; Member 2
         dw $B080        ; Member 3
         dw $B0B8        ; Member 4

; Cursor positions for name in SwdTech naming menu
C3C093:  dw $1C70        ; Letter 1
         dw $1C7C        ; Letter 2
         dw $1C88        ; Letter 3
         dw $1C94        ; Letter 4
         dw $1CA0        ; Letter 5
         dw $1CAC        ; Letter 6

; Cursor positions for SwdTech naming menu options
C3C0B3:  dw $5010        ; Row 1, column 1
         dw $5030        ; Row 1, column 2
         dw $5050        ; Row 1, column 3
         dw $5070        ; Row 1, column 4
         dw $5090        ; Row 1, column 5
         dw $50B0        ; Row 1, column 6
         dw $50D0        ; Row 1, column 7
         dw $6010        ; Row 2, column 1
         dw $6030        ; Row 2, column 2
         dw $6050        ; Row 2, column 3
         dw $6070        ; Row 2, column 4
         dw $6090        ; Row 2, column 5
         dw $60B0        ; Row 2, column 6
         dw $60D0        ; Row 2, column 7
         dw $7010        ; Row 3, column 1
         dw $7030        ; Row 3, column 2
         dw $7050        ; Row 3, column 3
         dw $7070        ; Row 3, column 4
         dw $7090        ; Row 3, column 5
         dw $70B0        ; Row 3, column 6
         dw $70D0        ; Row 3, column 7
         dw $8010        ; Row 4, column 1
         dw $8030        ; Row 4, column 2
         dw $8050        ; Row 4, column 3
         dw $8070        ; Row 4, column 4
         dw $8090        ; Row 4, column 5
         dw $80B0        ; Row 4, column 6
         dw $80D0        ; Row 4, column 7
         dw $9010        ; Row 5, column 1
         dw $9030        ; Row 5, column 2
         dw $9050        ; Row 5, column 3
         dw $9070        ; Row 5, column 4
         dw $9090        ; Row 5, column 5
         dw $90B0        ; Row 5, column 6
         dw $90D0        ; Row 5, column 7
         dw $A010        ; Row 6, column 1
         dw $A030        ; Row 6, column 2
         dw $A050        ; Row 6, column 3
         dw $A070        ; Row 6, column 4
         dw $A090        ; Row 6, column 5
         dw $A0B0        ; Row 6, column 6
         dw $A0D0        ; Row 6, column 7
         dw $B010        ; Row 7, column 1
         dw $B030        ; Row 7, column 2
         dw $B050        ; Row 7, column 3
         dw $B070        ; Row 7, column 4
         dw $B090        ; Row 7, column 5
         dw $B0B0        ; Row 7, column 6
         dw $B0D0        ; Row 7, column 7
         dw $C010        ; Row 8, column 1
         dw $C030        ; Row 8, column 2
         dw $C050        ; Row 8, column 3
         dw $C070        ; Row 8, column 4
         dw $C090        ; Row 8, column 5
         dw $C0B0        ; Row 8, column 6
         dw $C0D0        ; Row 8, column 7

; Cursor positions for main shop menu
C3C7F1:  dw $3408        ; BUY
         dw $3428        ; SELL
         dw $3448        ; EXIT

; Cursor positions for Buy menu
C3C80B:  dw $3408        ; Item 1
         dw $4008        ; Item 2
         dw $4C08        ; Item 3
         dw $5808        ; Item 4
         dw $6408        ; Item 5
         dw $7008        ; Item 6
         dw $7C08        ; Item 7
         dw $8808        ; Item 8

; ==============================[ Object data ]================================

; OAM for blank sprite
C3091A:  db $00          ; Tiles: 0

; Animation table for main cursor
C30912:  dw C30915       ; Sprite 1
         db $FE          ; Freeze

; OAM for hand cursor
C30915:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $3E00        ; Tile 0, pal 7, prio 3

; Animation table for blinking cursor
C3091B:  dw C30915       ; Show cursor
         db $02          ; Frames: 2
         dw C3091A       ; Hide cursor
         db $02          ; Frames: 2
         dw C30915       ; Bogus...
         db $FF          ; Loop

; Pointers to scrollbar animation tables
C30A46:  dw C30A57       ; Flashing up
         dw C30A60       ; Flashing down
         dw C30A4E       ; Flashing both ways

; Animation table for scrollbar flashing both ways
C30A4E:  dw C30A69       ; Flash neither
         db $10          ; Frames: 16
         dw C30A72       ; Flash both
         db $10          ; Frames: 16
         dw C30A69       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing up
C30A57:  dw C30A69       ; Flash neither
         db $10          ; Frames: 16
         dw C30A7B       ; Flash highest
         db $10          ; Frames: 16
         dw C30A69       ; Bogus...
         db $FF          ; Loop

; Animation table for scrollbar pointing down
C30A60:  dw C30A69       ; Flash neither
         db $10          ; Frames: 16
         dw C30A84       ; Flash lowest
         db $10          ; Frames: 16
         dw C30A69       ; Bogus...
         db $FF          ; Loop

; OAM for non-flashing scrollbar
C30A69:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE02  ; v: White

; OAM for scrollbar flashing both ways
C30A72:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE12  ; v: Black

; OAM for scrollbar pointing up
C30A7B:  db $02          ; Tiles: 2
         dw $0000,$3E12  ; ^: Black
         dw $0800,$BE02  ; v: White

; OAM for scrollbar pointing down
C30A84:  db $02          ; Tiles: 2
         dw $0000,$3E02  ; ^: White
         dw $0800,$BE12  ; v: Black

; Pointers to portrait animation tables
C30B54:  dw C30BF7       ; Portrait A
         dw C30C2F       ; Portrait B
         dw C30C67       ; Portrait C
         dw C30C9F       ; Portrait D

; Animation table for portrait A
C30BF7:  dw C30BFA       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait A
C30BFA:  db $0D          ; Tiles: 13
         dw $0080,$2060  ; Tile 1
         dw $0090,$2062  ; Tile 2
         dw $1080,$2064  ; Tile 3
         dw $1090,$2066  ; Tile 4
         dw $0020,$2068  ; Tile 5
         dw $0820,$2069  ; Tile 6
         dw $1020,$206A  ; Tile 7
         dw $1820,$206B  ; Tile 8
         dw $2020,$206C  ; Tile 9
         dw $2000,$206D  ; Tile 10
         dw $2008,$206E  ; Tile 11
         dw $2010,$206F  ; Tile 12
         dw $2018,$2078  ; Tile 13

; Animation table for portrait B
C30C2F:  dw C30C32       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait B
C30C32:  db $0D          ; Tiles: 13
         dw $0080,$2280  ; Tile 1
         dw $0090,$2282  ; Tile 2
         dw $1080,$2284  ; Tile 3
         dw $1090,$2286  ; Tile 4
         dw $0020,$2288  ; Tile 5
         dw $0820,$2289  ; Tile 6
         dw $1020,$228A  ; Tile 7
         dw $1820,$228B  ; Tile 8
         dw $2020,$228C  ; Tile 9
         dw $2000,$228D  ; Tile 10
         dw $2008,$228E  ; Tile 11
         dw $2010,$228F  ; Tile 12
         dw $2018,$2298  ; Tile 13

; Animation table for portrait C
C30C67:  dw C30C6A       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait C
C30C6A:  db $0D          ; Tiles: 13
         dw $0080,$24A0  ; Tile 1
         dw $0090,$24A2  ; Tile 2
         dw $1080,$24A4  ; Tile 3
         dw $1090,$24A6  ; Tile 4
         dw $0020,$24A8  ; Tile 5
         dw $0820,$24A9  ; Tile 6
         dw $1020,$24AA  ; Tile 7
         dw $1820,$24AB  ; Tile 8
         dw $2020,$24AC  ; Tile 9
         dw $2000,$24AD  ; Tile 10
         dw $2008,$24AE  ; Tile 11
         dw $2010,$24AF  ; Tile 12
         dw $2018,$24B8  ; Tile 13

; Animation table for portrait D
C30C9F:  dw C30CA2       ; Show portrait
         db $FE          ; Freeze

; OAM for portrait D
C30CA2:  db $0D          ; Tiles: 13
         dw $0080,$26C0  ; Tile 1
         dw $0090,$26C2  ; Tile 2
         dw $1080,$26C4  ; Tile 3
         dw $1090,$26C6  ; Tile 4
         dw $0020,$26C8  ; Tile 5
         dw $0820,$26C9  ; Tile 6
         dw $1020,$26CA  ; Tile 7
         dw $1820,$26CB  ; Tile 8
         dw $2020,$26CC  ; Tile 9
         dw $2000,$26CD  ; Tile 10
         dw $2008,$26CE  ; Tile 11
         dw $2010,$26CF  ; Tile 12
         dw $2018,$26D8  ; Tile 13

; Pointers for Config's large arrows
C33A9B:  dw C33A9F       ; Downward arrow
         dw C33AA8       ; Upward arrow

; Animation table for large downward arrow in Config menu
C33A9F:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C33AB1       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; Animation table for large upward arrow in Config menu
C33AA8:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C3C3BB       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow in Config menu
C33AB1:  db $01          ; Tiles: 1
         dw $B080        ; 16x16, X+0, Y+176
         dw $3E03        ; Tile 3, pal 7, prio 3

; Pointers for actor naming menu's large arrows
C37011:  dw C37015       ; Downward arrow
         dw C3701E       ; Upward arrow

; Animation table for large downward arrow in actor naming menu
C37015:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C37027       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; Animation table for large upward arrow in actor naming menu
C3701E:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C3C3BB       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow in actor naming menu
C37027:  db $01          ; Tiles: 1
         dw $A080        ; 16x16, X+0, Y+160
         dw $3E03        ; Tile 3, pal 7, prio 3

; Arrow's X positions in actor naming menu
C37066:  db $78          ; Letter 1
         db $80          ; Letter 2
         db $88          ; Letter 3
         db $90          ; Letter 4
         db $98          ; Letter 5
         db $A0          ; Letter 6

; X positions for candidates in Lineup menu
C37E5E:  db $18          ; Slot 1
         db $34          ; Slot 2
         db $50          ; Slot 3
         db $6C          ; Slot 4
         db $88          ; Slot 5
         db $A4          ; Slot 6
         db $C0          ; Slot 7
         db $DC          ; Slot 8
         db $18          ; Slot 9
         db $34          ; Slot 10
         db $50          ; Slot 11
         db $6C          ; Slot 12
         db $88          ; Slot 13
         db $A4          ; Slot 14
         db $C0          ; Slot 15
         db $DC          ; Slot 16

; Y positions for candidates in Lineup menu
C37E6E:  db $5C          ; Slot 1
         db $5C          ; Slot 2
         db $5C          ; Slot 3
         db $5C          ; Slot 4
         db $5C          ; Slot 5
         db $5C          ; Slot 6
         db $5C          ; Slot 7
         db $5C          ; Slot 8
         db $78          ; Slot 9
         db $78          ; Slot 10
         db $78          ; Slot 11
         db $78          ; Slot 12
         db $78          ; Slot 13
         db $78          ; Slot 14
         db $78          ; Slot 15
         db $78          ; Slot 16

; X positions for party members in Lineup menu
C38077:  db $18          ; Party 1 (NW)
         db $18          ; Party 1 (SW)
         db $38          ; Party 1 (NE)
         db $38          ; Party 1 (SE)
         db $68          ; Party 2 (NW)
         db $68          ; Party 2 (SW)
         db $88          ; Party 2 (NE)
         db $88          ; Party 2 (SE)
         db $B8          ; Party 3 (NW)
         db $B8          ; Party 3 (SW)
         db $D8          ; Party 3 (NE)
         db $D8          ; Party 3 (SE)

; Y positions for party members in Lineup menu
C3807B:  db $9C          ; NW
         db $B8          ; SW
         db $9C          ; NE
         db $B8          ; SE

; OAM for small white arrow in naming menus
C3C344:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E02        ; Tile 2, pal 7, prio 3

; OAM for small black arrow in naming menus
C3C349:  db $01          ; Tiles: 1
         dw $0009        ; 8x8, X+9, Y+0
         dw $3E12        ; Tile 18, pal 7, prio 3

; Animation table for small arrow in naming menus
C3C34E:  dw C3C344       ; White arrow
         db $02          ; Frames: 2
         dw C3C349       ; Black arrow
         db $02          ; Frames: 2
         dw C3C344       ; Bogus...
         db $FF          ; Loop

; Pointers for SwdTech naming menu's large arrows
C3C39F:  dw C3C3A3       ; Downward arrow
         dw C3C3AC       ; Upward arrow

; Animation table for large downward arrow in SwdTech naming menu
C3C3A3:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C3C3B6       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; Animation table for large upward arrow in SwdTech naming menu
C3C3AC:  dw C3091A       ; Hide arrow
         db $10          ; Frames: 16
         dw C3C3BB       ; Show arrow
         db $10          ; Frames: 16
         dw C3091A       ; Bogus...
         db $FF          ; Loop

; OAM for large downward arrow in SwdTech naming menu
C3C3B6:  db $01          ; Tiles: 1
         dw $8280        ; 16x16, X+0, Y+130
         dw $3E03        ; Tile 3, pal 7, prio 3

; OAM for large upward arrow
C3C3BB:  db $01          ; Tiles: 1
         dw $0080        ; 16x16, X+0, Y+0
         dw $BE03        ; Tile 3, pal 7, prio 3, V-Flip

; X positions for shop actors
C3D048:  db $18          ; Actor 1
         db $38          ; Actor 2
         db $58          ; Actor 3
         db $78          ; Actor 4
         db $98          ; Actor 5
         db $B8          ; Actor 6
         db $D8          ; Actor 7
         db $18          ; Actor 8
         db $38          ; Actor 9
         db $58          ; Actor 10
         db $78          ; Actor 11
         db $98          ; Actor 12
         db $B8          ; Actor 13
         db $D8          ; Actor 14

; Y positions for shop actors
C3D056:  db $9C          ; Actor 1
         db $9C          ; Actor 2
         db $9C          ; Actor 3
         db $9C          ; Actor 4
         db $9C          ; Actor 5
         db $9C          ; Actor 6
         db $9C          ; Actor 7
         db $B8          ; Actor 8
         db $B8          ; Actor 9
         db $B8          ; Actor 10
         db $B8          ; Actor 11
         db $B8          ; Actor 12
         db $B8          ; Actor 13
         db $B8          ; Actor 14

; X positions for actors on save files
C319E8:  dw $6850,$9880  ; File 1
         dw $6850,$9880  ; File 2
         dw $6850,$9880  ; File 3

; Y positions for actors on save files
C319F4:  dw $4040,$4040  ; File 1
         dw $7878,$7878  ; File 2
         dw $B0B0,$B0B0  ; File 3

; Actors' OAM complements when on "New Game"
C31A00:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 1
C31A0C:  dw $0000,$0000  ; File 1: None
         dw $0202,$0202  ; File 2: Grayscale
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 2
C31A18:  dw $0202,$0202  ; File 1: Grayscale
         dw $0000,$0000  ; File 2: None
         dw $0202,$0202  ; File 3: Grayscale

; Actors' OAM complements when on save file 3
C31A24:  dw $0202,$0202  ; File 1: Grayscale
         dw $0202,$0202  ; File 2: Grayscale
         dw $0000,$0000  ; File 3: None

; =============================[ Window layouts ]==============================

; Save and Load menus
C31905:  dw $58CB,$021C  ; 30x4 at $58CB (Top window)
C31909:  dw $59CB,$051C  ; 30x7 at $59CB (File A)
C3190D:  dw $5B8B,$051C  ; 30x7 at $5B8B (File B)
C31911:  dw $5D4B,$051C  ; 30x7 at $5D4B (File C)

; Main menu
C33256:  dw $60B9,$0207  ; 09x04 at $60B9 (Order; L part)
         dw $5885,$0201  ; 03x04 at $5885 (Order; R part)
C33262:  dw $588B,$181C  ; 30x26 at $588B (Party)
         dw $58B9,$0D05  ; 07x15 at $58B9 (Options)
         db $00          ; End

; Main menu and save file submenus
C3325A:  dw $5C79,$0205  ; 07x04 at $5C79 (Time)
         dw $5D75,$0507  ; 09x07 at $5D75 (Steps)
         db $00          ; End

; Save file submenus
C33266:  dw $58B5,$0A07  ; 09x12 at $58B5 (Yes/No)

; Config menu
C33AB6:  dw $590B,$161C  ; 30x24 at $590B (Main)
         dw $58B9,$0205  ; 07x04 at $58B9 (Title)
         db $00          ; End

; Cmd.Set menu
C34571:  dw $591F,$0412  ; 20x06 at $591F (Command set A)
         dw $5A9F,$0412  ; 20x06 at $5A9F (Command set B)
         dw $5C1F,$0412  ; 20x06 at $5C1F (Command set C)
         dw $5D9F,$0412  ; 20x06 at $5D9F (Command set D)
         dw $590B,$0408  ; 10x06 at $590B (Member name A)
         dw $5A8B,$0408  ; 10x06 at $5A8B (Member name B)
         dw $5C0B,$0408  ; 10x06 at $5C0B (Member name C)
         dw $5D8B,$0408  ; 10x06 at $5D8B (Member name D)
         dw $588B,$0108  ; 10x03 at $588B (Arrange)
         db $00          ; End

; Controller menu
C34A28:  dw $5B0B,$0B1C  ; 30x13 at $5B0B

; Button Settings menu
C34A7C:  dw $590B,$161C  ; 30x24 at $590B (Main)
         dw $58B3,$0208  ; 10x04 at $58B3 (Title)
         db $00          ; End

; Main Skills menu
C3545E:  dw $598B,$051C  ; 30x07 at $598B (Stats)
         dw $589B,$0214  ; 22x04 at $589B (Top)
         dw $5B4B,$0D1C  ; 30x15 at $5B4B (Bottom)
         dw $588B,$0406  ; 08x06 at $588B (Upper submenus)
         dw $5A0B,$0A06  ; 08x12 at $5A0B (Lower submenus)

; Skills submenus
         dw $618B,$051C  ; 30x07 at $618B (Stats)
         dw $634B,$0D1C  ; 30x15 at $634B (List)
         dw $609B,$0214  ; 22x04 at $609B (Description)
         dw $608B,$0206  ; 08x04 at $608B (Title)
         db $00          ; End

; Spell usage menu
C35E9E:  dw $589D,$1813  ; 21x26 at $589D (Party)
         dw $588B,$0207  ; 09x04 at $588B (Spell)
         dw $598B,$0307  ; 09x05 at $598B (MP cost)
         db $00          ; End

; Status menu
C365CF:  dw $588B,$181C  ; 30x26 at $588B (Main)
         dw $588B,$0105  ; 07x03 at $588B (Title)
         dw $5AEB,$0609  ; 11x08 at $5AEB (Commands)
         db $00          ; End

; Gogo's list of available commands
C365DB:  dw $58C7,$1200  ; 02x20 at $58C7 (Gogo, L part)
C365DF:  dw $6087,$1207  ; 09x20 at $6087 (Gogo, R part)

; Actor naming menu
C36E8C:  dw $589B,$0212  ; 20x04 at $589B (Name)
         dw $5997,$1416  ; 24x22 at $5997 (Options)
         dw $588B,$0505  ; 07x07 at $588B (Portrait)
         db $00          ; End

; Lineup menu
C37D2C:  dw $588B,$0206  ; 08x04 at $588B (Title)
         dw $5CCB,$071C  ; 30x09 at $5CCB (Parties)
         dw $598B,$051C  ; 30x07 at $598B (Stats)
         dw $5B0B,$061C  ; 30x08 at $5B0B (Candidates)
         dw $589B,$0214  ; 22x04 at $589B (Messages)
         dw $5D0B,$0608  ; 10x08 at $5D0B (Party 1)
         db $00          ; End

; Party boxes for Lineup menu
C37D44:  dw $5D33,$0608  ; 10x08 at $5D33 (Party 3)
C37D48:  dw $5D1F,$0608  ; 10x08 at $5D1F (Party 2)
         db $00          ; End

; Item menu and gear data menu
C385C2:  dw $60AD,$180D  ; 15x26 at $60AD (Gear stats; L part)
         dw $5885,$1801  ; 03x26 at $5885 (Gear stats; R part)
         dw $5ACB,$0F1C  ; 30x17 at $5ACB (Main)
         dw $598B,$031C  ; 30x05 at $598B (Description)
         dw $588B,$0204  ; 06x04 at $588B (Title)
         dw $5897,$0216  ; 24x04 at $5897 (Options)
         db $00          ; End

; Item usage menu
C391C5:  dw $589D,$1813  ; 21x26 at $589D (Party)
         dw $588B,$0208  ; 10x04 at $588B (Item)
         dw $598B,$0307  ; 09x05 at $598B (Quantity)
         db $00          ; End

; Party gear overview
C397D7:  dw $588B,$181C  ; 30x26 at $588B

; Equip and Relic menus
C39C6E:  dw $5B4B,$0D1C  ; 30x15 at $5B4B (Stats w/o title)
         dw $590B,$071C  ; 30x09 at $590B (Gear w/o title)
         dw $588B,$021C  ; 30x04 at $588B (Options)
         dw $634B,$0D1C  ; 30x15 at $634B (Stats w/ title)
         dw $610B,$071C  ; 30x09 at $610B (Gear w/ title)
         dw $60B9,$0205  ; 07x04 at $60B9 (Title)
         db $00          ; End

; Final battle lineup
C3B4B9:  dw $588B,$181C  ; 30x26 at $588B

; Colosseum item menu
C3B6F9:  dw $5899,$0215  ; 23x04 at $5899 ("Select...")
         dw $588B,$0205  ; 07x04 at $588B (Title)
         dw $598B,$031C  ; 30x05 at $598B (Description)
         dw $5ACB,$0F1C  ; 30x17 at $5ACB (Items)
         db $00          ; End

; Colosseum matchup menu
C3BCAC:  dw $588B,$020D  ; 15x4 at $588B (Prize)
         dw $58A9,$020D  ; 15x4 at $58A9 (Bet)
         dw $5CCB,$071C  ; 30x9 at $5CCB (Party)
         db $00          ; End

; SwdTech naming menu
C3C238:  dw $588B,$021C  ; 30x04 at $588B (Top)
         dw $598B,$021C  ; 30x04 at $598B (Middle)
         dw $5A8B,$101C  ; 30x18 at $5A8B (Bottom)
         db $00          ; End

; Sell menu and main shop menu
C3CB72:  dw $588B,$0207  ; 09x04 at $588B (Title)
         dw $589D,$0213  ; 21x04 at $589D (Dialogue)
         dw $598B,$020C  ; 14x04 at $598B (Options)
         dw $59A7,$020E  ; 16x04 at $59A7 (GP)
         dw $5A8B,$101C  ; 30x18 at $5A8B (Items)

; Buy menu
         dw $608B,$0207  ; 09x04 at $608B (Title)
         dw $609D,$0213  ; 21x04 at $609D (Dialogue)
         dw $618B,$0C11  ; 19x14 at $618B (Items)
         dw $61B1,$0C09  ; 11x14 at $61B1 (Amounts)
         dw $650B,$061C  ; 30x08 at $650B (Actors)

; Shop order menus
         dw $688B,$0207  ; 09x04 at $688B (Title)
         dw $689D,$0213  ; 21x04 at $689D (Dialogue)
         dw $698B,$0711  ; 19x09 at $698B (Item)
         dw $6BCB,$031C  ; 30x05 at $6BCB (Description)
         dw $6D0B,$061C  ; 30x08 at $6D0B (Actors)
         dw $69B1,$0709  ; 11x09 at $69B1 (Amounts)
         db $00          ; End

; ==========================[ Text shifting tables ]===========================

; Text shifting table for save file confirmation, Colosseum matchup
C31959:  db $20,$00,$00  ; 32 lines, shift by 0 px
         db $0C,$04,$00  ; 12 lines, shift by 4 px
         db $0C,$08,$00  ; 12 lines, shift by 8 px
         db $08,$C8,$FF  ; 8 lines, shift by -38 px
         db $50,$00,$00  ; 80 lines, shift by 0 px
         db $58,$00,$00  ; 88 lines, shift by 0 px
         db $00          ; End

; Text shifting table for main menu
C3378A:  db $0F,$00,$00  ; Nothing
         db $0F,$03,$00  ; Item
         db $0F,$04,$00  ; Skills
         db $0F,$05,$00  ; Equip
         db $0F,$06,$00  ; Relic
         db $0F,$07,$00  ; Status
         db $0F,$08,$00  ; Config
         db $0F,$09,$00  ; Save
         db $07,$08,$00  ; Nothing
         db $08,$00,$00  ; Nothing
         db $08,$00,$00  ; Time
         db $18,$00,$00  ; The rest
         db $00          ; End

; Text shifting table for Cmd.Set menu
C3476F:  db $1F,$00,$00  ; Arrange
         db $0C,$04,$00  ; Row 1
         db $0C,$08,$00  ; Row 2
         db $24,$0C,$00  ; Row 3, row 4
         db $0C,$10,$00  ; Row 5
         db $24,$14,$00  ; Row 6, row 7
         db $0C,$18,$00  ; Row 8
         db $24,$1C,$00  ; Row 9, row 10
         db $0C,$20,$00  ; Row 11
         db $24,$24,$00  ; Row 12
         db $00          ; End

; Text shifting table for Button Settings menu
C34AA3:  db $2F,$00,$00  ; Title, A
         db $0C,$04,$00  ; A's options
         db $0C,$08,$00  ; B
         db $0C,$0C,$00  ; B's options
         db $0C,$10,$00  ; X
         db $0C,$14,$00  ; X's options
         db $0C,$18,$00  ; Y
         db $0C,$1C,$00  ; Y's options
         db $0C,$20,$00  ; L
         db $0C,$24,$00  ; L's options
         db $0C,$28,$00  ; R
         db $0C,$2C,$00  ; R's options
         db $0C,$30,$00  ; Select
         db $0C,$34,$00  ; Select's options
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; BG3 V-Shift table for skill menus
C354EC:  db $4F,$02,$00  ; SwdTech and above
         db $40,$02,$00  ; Blitz and below
         db $00          ; End

; BG1 H-Shift table for skill menus (merges tilemaps)
C35538:  db $27,$00,$01  ; Nothing
         db $3C,$00,$01  ; Member stats
         db $6C,$00,$00  ; Spells, etc.
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for skill menus (condenses text)
C35545:  db $3F,$00,$00  ; LV
         db $0C,$04,$00  ; HP
         db $0C,$08,$00  ; MP
         db $0A,$0C,$00  ; Nothing
         db $01,$0C,$00  ; Nothing
         db $01,$0C,$00  ; Nothing
         db $04,$A0,$FF  ; Ability row A
         db $04,$A0,$FF  ; Ability row B
         db $04,$A0,$FF  ; Ability row C
         db $04,$A4,$FF  ; Ability row D
         db $04,$A4,$FF  ; Ability row E
         db $04,$A4,$FF  ; Ability row F
         db $04,$A8,$FF  ; Ability row G
         db $04,$A8,$FF  ; Ability row H
         db $04,$A8,$FF  ; Ability row I
         db $04,$AC,$FF  ; Ability row J
         db $04,$AC,$FF  ; Ability row K
         db $04,$AC,$FF  ; Ability row L
         db $04,$B0,$FF  ; Ability row M
         db $04,$B0,$FF  ; Ability row N
         db $04,$B0,$FF  ; Ability row O
         db $04,$B4,$FF  ; Ability row P
         db $04,$B4,$FF  ; Ability row Q
         db $04,$B4,$FF  ; Ability row R
         db $04,$B8,$FF  ; Ability row S
         db $04,$B8,$FF  ; Ability row T
         db $04,$B8,$FF  ; Ability row U
         db $04,$BC,$FF  ; Ability row V
         db $04,$BC,$FF  ; Ability row W
         db $04,$BC,$FF  ; Ability row X
         db $04,$C0,$FF  ; Ability row Y
         db $04,$C0,$FF  ; Ability row Z
         db $04,$C0,$FF  ; Ability row Þ
         db $1E,$20,$FF  ; Nothing?
         db $00          ; End

; Text shifting table for Status menu
C36873:  db $27,$00,$00  ; Status
         db $0C,$04,$00  ; Cmd choice A
         db $0C,$08,$00  ; Cmd choice B
         db $0C,$0C,$00  ; Cmd choice C
         db $0C,$10,$00  ; Cmd choice D
         db $0C,$14,$00  ; Command A
         db $0C,$18,$00  ; Command B
         db $0C,$1C,$00  ; Command C
         db $0C,$20,$00  ; Command D
         db $0C,$24,$00  ; Needed exp.
         db $0C,$28,$00  ; Bat.Pwr
         db $0C,$2C,$00  ; Defense
         db $0C,$30,$00  ; Evade
         db $0C,$34,$00  ; Mag.Def
         db $0C,$38,$00  ; MBlock
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; BG1 H-Shift table for actor naming menu (merges tilemaps)
C36FB0:  db $2F,$00,$01  ; Actor name
         db $50,$00,$00  ; Upper chars
         db $50,$00,$00  ; Lower chars
         db $10,$00,$01  ; Blank area
         db $00          ; End

; BG1 V-Shift table for actor naming menu (condenses text)
C36FBD:  db $2F,$00,$00  ; Actor name
         db $50,$D0,$FF  ; Upper chars
         db $50,$D0,$FF  ; Lower chars
         db $10,$00,$00  ; Blank area
         db $00          ; End

; Text shifting table for Lineup menu
C37D78:  db $20,$02,$00  ; Title
         db $08,$00,$00  ; Nothing
         db $0B,$04,$00  ; Nothing
         db $0C,$08,$00  ; Level
         db $0C,$0C,$00  ; HP
         db $0C,$10,$00  ; MP
         db $00          ; End

; BG1 H-Shift table for inventory-style menus
C38689:  db $28,$00,$01  ; Nothing
         db $2F,$00,$01  ; Nothing
         db $78,$00,$00  ; Items
         db $1E,$00,$01  ; Nothing
         db $00          ; End

; BG1 V-Shift table for inventory-style menus
C38696:  db $27,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $08,$80,$00  ; Nothing?
         db $08,$00,$00  ; Nothing?
         db $04,$AC,$FF  ; Item row 1
         db $04,$AC,$FF  ; Item row 2
         db $04,$AC,$FF  ; Item row 3
         db $04,$B0,$FF  ; Item row 4
         db $04,$B0,$FF  ; Item row 5
         db $04,$B0,$FF  ; Item row 6
         db $04,$B4,$FF  ; Item row 7
         db $04,$B4,$FF  ; Item row 8
         db $04,$B4,$FF  ; Item row 9
         db $04,$B8,$FF  ; Item row 10
         db $04,$B8,$FF  ; Item row 11
         db $04,$B8,$FF  ; Item row 12
         db $04,$BC,$FF  ; Item row 13
         db $04,$BC,$FF  ; Item row 14
         db $04,$BC,$FF  ; Item row 15
         db $04,$C0,$FF  ; Item row 16
         db $04,$C0,$FF  ; Item row 17
         db $04,$C0,$FF  ; Item row 18
         db $04,$C4,$FF  ; Item row 19
         db $04,$C4,$FF  ; Item row 20
         db $04,$C4,$FF  ; Item row 21
         db $04,$C8,$FF  ; Item row 22
         db $04,$C8,$FF  ; Item row 23
         db $04,$C8,$FF  ; Item row 24
         db $04,$CC,$FF  ; Item row 25
         db $04,$CC,$FF  ; Item row 26
         db $04,$CC,$FF  ; Item row 27
         db $04,$D0,$FF  ; Item row 28
         db $04,$D0,$FF  ; Item row 29
         db $04,$D0,$FF  ; Item row 30
         db $1E,$00,$00  ; Nothing
         db $00          ; End

; BG3 V-Shift table for Item and Colosseum menus
C38706:  db $2F,$00,$00  ; Title
         db $0C,$04,$00  ; Desc row 1
         db $0C,$08,$00  ; Desc row 2
         db $0C,$0C,$00  ; 2-hand
         db $0C,$10,$00  ; 50% Dmg
         db $0C,$14,$00  ; Vigor
         db $0C,$18,$00  ; Speed
         db $0C,$1C,$00  ; Stamina
         db $0C,$20,$00  ; Mag.Pwr
         db $0C,$24,$00  ; Bat.Pwr
         db $0C,$28,$00  ; Defense
         db $0C,$2C,$00  ; Evade
         db $0C,$30,$00  ; Mag.Def
         db $0C,$34,$00  ; MBlock
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; BG1 H-Shift table for gear list browsing
C39D53:  db $27,$00,$01  ; Nothing?
         db $3C,$00,$01  ; Nothing?
         db $6C,$00,$00  ; Item list
         db $1E,$00,$01  ; Nothing?
         db $00          ; End

; BG1 V-Shift table for gear list browsing
C39D60:  db $3F,$00,$00  ; Nothing?
         db $0C,$04,$00  ; Nothing?
         db $0C,$08,$00  ; Nothing?
         db $0A,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $01,$0C,$00  ; Nothing?
         db $04,$A0,$FF  ; Item row 1
         db $04,$A0,$FF  ; Item row 2
         db $04,$A0,$FF  ; Item row 3
         db $04,$A4,$FF  ; Item row 4
         db $04,$A4,$FF  ; Item row 5
         db $04,$A4,$FF  ; Item row 6
         db $04,$A8,$FF  ; Item row 7
         db $04,$A8,$FF  ; Item row 8
         db $04,$A8,$FF  ; Item row 9
         db $04,$AC,$FF  ; Item row 10
         db $04,$AC,$FF  ; Item row 11
         db $04,$AC,$FF  ; Item row 12
         db $04,$B0,$FF  ; Item row 13
         db $04,$B0,$FF  ; Item row 14
         db $04,$B0,$FF  ; Item row 15
         db $04,$B4,$FF  ; Item row 16
         db $04,$B4,$FF  ; Item row 17
         db $04,$B4,$FF  ; Item row 18
         db $04,$B8,$FF  ; Item row 19
         db $04,$B8,$FF  ; Item row 20
         db $04,$B8,$FF  ; Item row 21
         db $04,$BC,$FF  ; Item row 22
         db $04,$BC,$FF  ; Item row 23
         db $04,$BC,$FF  ; Item row 24
         db $04,$C0,$FF  ; Item row 25
         db $04,$C0,$FF  ; Item row 26
         db $04,$C0,$FF  ; Item row 27
         db $1E,$10,$00  ; Nothing?
         db $00          ; End

; V-Shift table for gear menus and final battle lineup
C39DC7:  db $0F,$00,$00  ; Nothing
         db $0C,$04,$00  ; Options, title
         db $0C,$08,$00  ; Reequip mode
         db $0C,$0C,$00  ; R-Hand
         db $0C,$10,$00  ; L-Hand
         db $0C,$14,$00  ; Head, Relic 1
         db $0C,$18,$00  ; Body, Relic 2
         db $0C,$1C,$00  ; Member 2's armor
         db $0C,$20,$00  ; Vigor
         db $0C,$24,$00  ; Speed
         db $0C,$28,$00  ; Stamina
         db $0C,$2C,$00  ; Mag.Pwr
         db $0C,$30,$00  ; Bat.Pwr
         db $0C,$34,$00  ; Defense
         db $0C,$38,$00  ; Evade
         db $0C,$3C,$00  ; Mag.Def
         db $0C,$40,$00  ; MBlock
         db $00          ; End

; BG3 H-Shift table for SwdTech naming menu (merges tilemaps)
C3BDE6:  db $4F,$00,$01  ; Title, desc
         db $50,$00,$00  ; Option rows 1-5
         db $30,$00,$00  ; Option rows 6-8
         db $10,$00,$01  ; Offscreen row
         db $00          ; End

; BG3 V-Shift table for SwdTech naming menu (condenses text)
C3BDF3:  db $4F,$02,$00  ; Title, desc
         db $50,$B0,$FF  ; Option rows 1-5
         db $30,$B0,$FF  ; Option rows 6-8
         db $10,$00,$00  ; Offscreen row
         db $00          ; End

; BG3 text shifting table for shop
C3CF92:  db $2F,$04,$00  ; Title
         db $0C,$04,$00  ; Item 1
         db $0C,$08,$00  ; Item 2
         db $0C,$0C,$00  ; Item 3
         db $0C,$10,$00  ; Item 4
         db $0C,$14,$00  ; Item 5
         db $0C,$18,$00  ; Item 6
         db $0C,$1C,$00  ; Item 7
         db $0C,$20,$00  ; Item 8
         db $0C,$24,$00  ; Nothing
         db $0C,$28,$00  ; Nothing
         db $0C,$2C,$00  ; Nothing
         db $0C,$30,$00  ; Nothing
         db $0C,$34,$00  ; Nothing
         db $0C,$38,$00  ; Nothing
         db $0C,$3C,$00  ; Nothing
         db $00          ; End

; Shift amount for 1st of every 3 rows of list scrolling down
C388E0:  dw $0008        ; Frame 3: +8 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 1st of every 3 rows of list scrolling up
C388E6:  dw $FFFC        ; Frame 3: +4 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFF8        ; Frame 1: +8 px up

; Shift amount for 2nd of every 3 rows of list scrolling down
C388EC:  dw $0004        ; Frame 3: +4 px down
         dw $0008        ; Frame 2: +8 px down
         dw $0004        ; Frame 1: +4 px down

; Shift amount for 2nd of every 3 rows of list scrolling up
C388F2:  dw $FFFC        ; Frame 3: +4 px up
         dw $FFF8        ; Frame 2: +8 px up
         dw $FFFC        ; Frame 1: +4 px up

; Shift amount for every 3rd row of list scrolling down
C388F8:  dw $0004        ; Frame 3: +4 px down
         dw $0004        ; Frame 2: +4 px down
         dw $0008        ; Frame 1: +8 px down

; Shift amount for every 3rd row of list scrolling up
C388FE:  dw $FFF8        ; Frame 3: +8 px up
         dw $FFFC        ; Frame 2: +4 px up
         dw $FFFC        ; Frame 1: +4 px up

; ============================[ Tilemap pointers ]=============================

; Tilemap pointers for Mag.Order strings
C341AD:  dw $42E9        ; Spell type C
         dw $4269        ; Spell type B
         dw $41E9        ; Spell type A

; Tilemap pointers for wallpaper values
C34204:  dw $43A5        ; 1
         dw $43A9        ; 2
         dw $43AD        ; 3
         dw $43B1        ; 4
         dw $43B5        ; 5
         dw $43B9        ; 6
         dw $43BD        ; 7
         dw $43C1        ; 8

; Tilemap pointers for stats in Lineup menu
C3817A:  dw $3A77        ; LV
         dw $3AF3        ; HP
         dw $3AFD        ; Max HP
         dw $3B73        ; MP
         dw $3B7D        ; Max MP

; X positions for party gear overview
C3977E:  db $07          ; R-Hand
         db $15          ; L-Hand
         db $07          ; Head
         db $15          ; Body
         db $07          ; Relic 1
         db $15          ; Relic 2

; Relative Y positions for party gear overview
C39784:  db $00          ; R-Hand
         db $00          ; L-Hand
         db $02          ; Head
         db $02          ; Body
         db $04          ; Relic 1
         db $04          ; Relic 2

; Tilemap pointers for stats of member 1
C333C8:  dw $39A7        ; Level
         dw $39E3        ; HP
         dw $39ED        ; Max HP
         dw $3A23        ; MP
         dw $3A2D        ; Max MP

; Tilemap pointers for stats of member 2
C33414:  dw $3B27        ; Level
         dw $3B63        ; HP
         dw $3B6D        ; Max HP
         dw $3BA3        ; MP
         dw $3BAD        ; Max MP

; Tilemap pointers for stats of member 3
C33460:  dw $3CA7        ; Level
         dw $3CE3        ; HP
         dw $3CED        ; Max HP
         dw $3D23        ; MP
         dw $3D2D        ; Max MP

; Tilemap pointers for stats of member 4
C334AC:  dw $3E27        ; Level
         dw $3E63        ; HP
         dw $3E6D        ; Max HP
         dw $3EA3        ; MP
         dw $3EAD        ; Max MP

; Tilemap pointers for Bat.Speed values
C33CBA:  dw $3A25        ; 1
         dw $3A29        ; 2
         dw $3A2D        ; 3
         dw $3A31        ; 4
         dw $3A35        ; 5
         dw $3A39        ; 6

; Tilemap pointers for Msg.Speed values
C33CFB:  dw $3AA5        ; 1
         dw $3AA9        ; 2
         dw $3AAD        ; 3
         dw $3AB1        ; 4
         dw $3AB5        ; 5
         dw $3AB9        ; 6

; Tilemap pointers for Mag.Order values
C3414F:  dw $41A5        ; 1
         dw $41A9        ; 2
         dw $41AD        ; 3
         dw $41B1        ; 4
         dw $41B5        ; 5
         dw $41B9        ; 6

; Tilemap pointers for stats in Skills menu
C355E1:  dw $4237        ; Level
         dw $42B3        ; HP
         dw $42BD        ; Max HP
         dw $4333        ; MP
         dw $433D        ; Max MP

; Tilemap pointers for stats in Status menu
C366EC:  dw $3A27        ; Level
         dw $3A63        ; HP
         dw $3A6D        ; Max HP
         dw $3AA3        ; MP
         dw $3AAD        ; Max MP

; Text positions for gear data menu
C38DDD:  dw $7DCF        ; Actor name 1
         dw $7DE3        ; Actor name 2
         dw $7DF7        ; Actor name 3
         dw $7E4F        ; Actor name 4
         dw $7E63        ; Actor name 5
         dw $7E77        ; Actor name 6
         dw $7ECF        ; Actor name 7
         dw $7EE3        ; Actor name 8
         dw $7EF7        ; Actor name 9
         dw $7F4F        ; Actor name 10
         dw $7F63        ; Actor name 11
         dw $7F77        ; Actor name 12
         dw $7FCF        ; Actor name 13
         dw $7FE3        ; Actor name 14
;        dw $7FF7        ; Actor name 15 (unused)

; Tilemap pointers for Buy menu
C3C959:  dw $79CF        ; Item 1
         dw $7A4F        ; Item 2
         dw $7ACF        ; Item 3
         dw $7B4F        ; Item 4
         dw $7BCF        ; Item 5
         dw $7C4F        ; Item 6
         dw $7CCF        ; Item 7
         dw $7D4F        ; Item 8

; ==================================[ Text ]===================================

; Positioned text for save menus
C31A8D:  dw $7A4F : db "EMPTY",$00
C31A95:  dw $7C0F : db "EMPTY",$00
C31A9D:  dw $7DCF : db "EMPTY",$00
C31AA5:  dw $7ACF : db "TIME",$00
C31AAC:  dw $7C8F : db "TIME",$00
C31AB3:  dw $7E4F : db "TIME",$00
C31ABA:  dw $7B11 : db ":",$00
C31ABE:  dw $7CD1 : db ":",$00
C31AC2:  dw $7E91 : db ":",$00
C31AC6:  dw $7A7B : db "LV",$00
C31ACB:  dw $7C3B : db "LV",$00
C31AD0:  dw $7DFB : db "LV",$00
C31AD5:  dw $7AFB : db "/",$00
C31AD9:  dw $7CBB : db "/",$00
C31ADD:  dw $7E7B : db "/",$00
C31AE1:  dw $7925 : db |セーブ[end]|	; Save
C31AE7:  dw $7923 : db |ニューゲーム[end]|	; New Game

; Ordered list of item icons for Arrange command
C32768:  db $FF          ; No icon
         db $E3          ; Dirk
         db $E4          ; Sword
         db $E5          ; Lance
         db $E6          ; Knife
         db $E7          ; Rod
         db $E8          ; Brush
         db $E9          ; Stars
         db $EA          ; Special
         db $EB          ; Gambler
         db $EC          ; Claw
         db $ED          ; Shield
         db $F0          ; Helmet
         db $F1          ; Armor
         db $F2          ; Tool
         db $F3          ; Skean
         db $F4          ; Relic

; Text, "Wounded "
C337E3:  db |せんとうふのう |

; Text pointers for main menu and save file submenus
C337EB:  dw C338C5       ; TIME
         dw C338D0       ; Steps
         dw C33920       ; Order
C337F1:  dw C33893       ; Item
         dw C3389A       ; Skills
         dw C338A7       ; Relic
         dw C338AF       ; Status
C337F9:  dw C33846       ; /
         dw C3384A       ; /
C337FD:  dw C3385D       ; /
         dw C33861       ; /
C33801:  dw C33874       ; /
         dw C33878       ; /
C33805:  dw C3388B       ; /
         dw C3388F       ; /
C33809:  dw C33837       ; LV
         dw C3383C       ; HP
         dw C33841       ; MP
C3380F:  dw C3384E       ; LV
         dw C33853       ; HP
         dw C33858       ; MP
C33815:  dw C33865       ; LV
         dw C3386A       ; HP
         dw C3386F       ; MP
C3381B:  dw C3387C       ; LV
         dw C33881       ; HP
         dw C33886       ; MP
C33821:  dw C338A1       ; Equip
         dw C338B7       ; Config
C33825:  dw C338DB       ; Yes
         dw C338E0       ; No
         dw C338E6       ; This
         dw C338EF       ; data?
C3382D:  dw C338DB       ; Yes
         dw C338E0       ; No
         dw C338F9       ; Erasing
         dw C33902       ; data.
         dw C3390C       ; Okay?

; Positioned text for main menu and save file submenus
C33837:  dw $399D : db "LV",$00
C3383C:  dw $39DD : db "HP",$00
C33841:  dw $3A1D : db "MP",$00
C33846:  dw $39EB : db "/",$00
C3384A:  dw $3A2B : db "/",$00
C3384E:  dw $3B1D : db "LV",$00
C33853:  dw $3B5D : db "HP",$00
C33858:  dw $3B9D : db "MP",$00
C3385D:  dw $3B6B : db "/",$00
C33861:  dw $3BAB : db "/",$00
C33865:  dw $3C9D : db "LV",$00
C3386A:  dw $3CDD : db "HP",$00
C3386F:  dw $3D1D : db "MP",$00
C33874:  dw $3CEB : db "/",$00
C33878:  dw $3D2B : db "/",$00
C3387C:  dw $3E1D : db "LV",$00
C33881:  dw $3E5D : db "HP",$00
C33886:  dw $3E9D : db "MP",$00
C3388B:  dw $3E6B : db "/",$00
C3388F:  dw $3EAB : db "/",$00
C33893:  dw $793B : db |アイテム[end]|	; Item
C3389A:  dw $79BB : db |とくしゅ[end]|	; Skills
C338A1:  dw $79FB : db |そうび[end]|	; Equip
C338A7:  dw $7ABB : db |アクセサリ[end]|	; Relic
C338AF:  dw $7B3B : db |ステータス[end]|	; Status
C338B7:  dw $7B7B : db |コンフィグ[end]|	; Config
C338BF:  dw $7BFB : db |セーブ[end]|	; Save
C338C5:  dw $7CBB : db "TIME",$00
C338CC:  dw $7CFF : db ":",$00
C338D0:  dw $7DB7 : db |ほすう[end]|	; Steps
C338D6:  dw $7E37 : db |ギル[end]|	; Gp
C338DB:  dw $7A7D : db |はい[end]|	; Yes
C338E0:  dw $7AFD : db |いいえ[end]|	; No
C338E6:  dw $78F7 : db |このデータで[end]|	; This
C338EF:  dw $7977 : db |はじめますか?[end]|	; data?
C338F9:  dw $78F7 : db |これをけして[end]|	; Erasing
C33902:  dw $7977 : db |かきこみます。[end]|	; data.
C3390C:  dw $79F7 : db |いいですか?[end]|	; Okay?
C33920:  dw $813D : db |たいけい[end]|	; Order

; Text pointers for color selection arrow
C3426E:  dw C34288       ; Window 1
         dw C3428C       ; Window 2
         dw C34290       ; Window 3
         dw C34294       ; Window 4
         dw C34298       ; Window 5
         dw C3429C       ; Window 6
         dw C342A0       ; Window 7

; Positioned spaces for blanking color selection arrow
C3427E:  dw $44F5 : db "       ",$00

; Positioned arrows for wallpaper colors
C34288:  dw $44F5 : db |↑[end]|   ; Color 1
C3428C:  dw $44F7 : db |↑[end]|   ; Color 2
C34290:  dw $44F9 : db |↑[end]|   ; Color 3
C34294:  dw $44FB : db |↑[end]|   ; Color 4
C34298:  dw $44FD : db |↑[end]|   ; Color 5
C3429C:  dw $44FF : db |↑[end]|   ; Color 6
C342A0:  dw $4501 : db |↑[end]|   ; Color 7

; Text pointers for Config menu
C34E81:  dw C34E97       ; Bat.Mode
         dw C34EA0       ; Bat.Speed
         dw C34EA7       ; Msg.Speed
         dw C34EAF       ; Cmd.Set
         dw C34EB9       ; Gauge
         dw C34EBF       ; Sound
         dw C34EC6       ; Reequip
         dw C34F0C       ; Mag.Order
         dw C34F18       ; Window
         dw C34F20       ; Color
C34DF5:  dw C34DFD       ; Controller
         dw C34E78       ; Cursor
C34EFA:  dw C34F35       ; «========»
         dw C34F42       ; «========»
         dw C34F4F       ; «========»
C34F00:  dw C34E0E       ; Fast
         dw C34E14       ; Slow
         dw C34F5C       ; R
         dw C34F60       ; G
         dw C34F64       ; B
         dw C34F26       ; 1‥
         dw C34F2B       ; 2‥
         dw C34F30       ; 3‥

; Positioned text for Config page 1
C34DFD:  dw $3D8F : db |コントローラー[end]|		; Controller
C34E07:  dw $39B5 : db |ウェイト[end]|		; Wait
C34E0E:  dw $3A65 : db |はやい[end]|		; Fast
C34E14:  dw $3A75 : db |おそい[end]|		; Slow
C34E1A:  dw $3B35 : db |たんしゅく[end]|		; Short
C34E22:  dw $3BA5 : db |オン[end]| 		; On
C34E27:  dw $3BB5 : db |オフ[end]| 		; Off
C34E2C:  dw $3C25 : db |ステレオ[end]|		; Stereo
C34E33:  dw $3C35 : db |モノラル[end]|		; Mono
C34E3A:  dw $3CB5 : db |きおく[end]|		; Memory
C34E40:  dw $3D25 : db |さいきょう[end]|		; Optimum
C34E48:  dw $3DA5 : db |ノーマル[end]|		; Normal
C34E4F:  dw $3DB5 : db |カスタム[end]|		; Custom
C34E56:  dw $3E35 : db |マルチ[end]|		; Multiple
C34E5C:  dw $3A25 : db "1 2 3 4 5 6",$00
C34E6A:  dw $3AA5 : db "1 2 3 4 5 6",$00
C34E78:  dw $3C8F : db |カーソルいち[end]|		; Cursor

; Positioned text for Config page 1
C34E8F:  dw $78BB : db |コンフィグ[end]|		; Config
C34E97:  dw $394F : db |バトルモード[end]|		; Bat.Mode
C34EA0:  dw $39D3 : db |スピード[end]|		; Bat.Speed
C34EA7:  dw $3A53 : db |メッセージ[end]|		; Msg.Speed
C34EAF:  dw $3AD3 : db |コマンドしてい[end]|		; Cmd.Set
C34EB9:  dw $3B53 : db |ゲージ[end]|		; Gauge
C34EBF:  dw $3BCF : db |サウンド[end]|		; Sound
C34EC6:  dw $3CCF : db |さいそうび[end]|		; Reequip
C34ECE:  dw $3965 : db |アクティヴ[end]|		; Active
C34ED6:  dw $3AE5 : db |ウィンドウ[end]|		; Window
C34EDE:  dw $3C65 : db |もどす[end]|		; Reset
C34EE4:  dw $3CF5 : db |すべてはずす[end]|		; Empty
C34EED:  dw $3DE5 : db |シングル[end]|		; Single

; Positioned text for Config page 2
C34F0C:  dw $414F : db |まほうのならびかた[end]|		; Mag.Order
C34F18:  dw $434F : db |ウィンドウ[end]|		; Window
C34F20:  dw $43CF : db |カラー[end]|		; Color
C34F26:  dw $4225 : db |１‥[end]|
C34F2B:  dw $42A5 : db |２‥[end]|
C34F30:  dw $4325 : db |３‥[end]|
C34F35:  dw $452D : db "«±±±±±±±±»",$00
C34F42:  dw $45AD : db "«±±±±±±±±»",$00
C34F4F:  dw $462D : db "«±±±±±±±±»",$00
C34F5C:  dw $4525 : db "R",$00
C34F60:  dw $45A5 : db "G",$00
C34F64:  dw $4625 : db "B",$00
C34F68:  dw $43A5 : db "1 2 3 4 5 6 7 8",$00
C34F7A:  dw $41A5 : db "1 2 3 4 5 6",$00
C34F88:  dw $4425 : db |フォント[end]|		; Font
C34F8F:  dw $43F5 : db |ウィンドウ[end]|		; Window
C34F9D:  dw $44B5 : db !pal1,!pal2,!pal3,!pal4,!pal5,!pal6,!pal7,$00

; Relative pointers to Mag.Order strings
C341B3:  db $00,$04,$08  ; Healing, Attack, Effect
         db $00          ; ...
         db $00,$08,$04  ; Healing, Effect, Attack
         db $00          ; ...
         db $04,$08,$00  ; Attack, Effect, Healing
         db $00          ; ...
         db $04,$00,$08  ; Attack, Healing, Effect
         db $00          ; ...
         db $08,$00,$04  ; Effect, Healing, Attack
         db $00          ; ...
         db $08,$04,$00  ; Effect, Attack, Healing

; Mag.Order strings
C34FA7:  db |かいふく|				; Healing
C34FAB:  db |こうげき|				; Attack
C34FAF:  db |かんせつ|				; Effect

; Positioned text for Cmd.Set menu
C34FB3:  dw $788F : db |せいとん[end]|		; Arrange

; Positioned text for Controller menu
C34FBA:  dw $7B4D : db |コントローラーのわりふり[end]|	; Controller
C34FC9:  dw $7C21 : db |コントローラー１[end]|		; Cntlr1
C34FD4:  dw $7C33 : db |コントローラー２[end]|		; Cntlr2
C34FDF:  dw $7CA1 : db |コントローラー１[end]|		; Cntlr1
C34FEA:  dw $7CB3 : db |コントローラー２[end]|		; Cntlr2
C34FF5:  dw $7D21 : db |コントローラー１[end]|		; Cntlr1
C35000:  dw $7D33 : db |コントローラー２[end]|		; Cntlr2
C3500B:  dw $7DA1 : db |コントローラー１[end]|		; Cntlr1
C35016:  dw $7DB3 : db |コントローラー２[end]|		; Cntlr2

; Text pointers for Button Settings menu
C35021:  dw C35093             			; Button Settings
         dw C351CB             			; A: button
         dw C351D1            			; B: button
         dw C351D7         			; X: button
         dw C351DD           			; Y: button
         dw C351E3          			; L: button
         dw C351E9            			; R: button
         dw C351EF          			; S: button
C35031:  dw C351F5      			; A
         dw C351F9         			; B
         dw C351FD          			; X
         dw C35201              		; Y
         dw C35205             			; L
         dw C35209                  		; R
         dw C3520D               		; SEL
C3503F:  dw C3509E                  		; A: Decision
         dw C350A5                      	; A: Cancel
         dw C350AC                      	; A: Menu
         dw C350B3                      	; A: Party
         dw C350BB                      	; A: Change
         dw C350C2                      	; A: Defense
C3504B:  dw C350C9                      	; B: Decision
         dw C350D0                      	; B: Cancel
         dw C350D7                      	; B: Menu
         dw C350DE                      	; B: Party
         dw C350E6                      	; B: Change
         dw C350ED                      	; B: Defense
C35057:  dw C350F4                      	; X: Decision
         dw C350FB                      	; X: Cancel
         dw C35102                      	; X: Menu
         dw C35109                      	; X: Party
         dw C35111                      	; X: Change
         dw C35118                      	; X: Defense
C35063:  dw C3511F                      	; Y: Decision
         dw C35126                      	; Y: Cancel
         dw C3512D                      	; Y: Menu
         dw C35134                      	; Y: Party
         dw C3513C                      	; Y: Change
         dw C35143                      	; Y: Defense
C3506F:  dw C3514A                      	; L: Decision
         dw C35151                      	; L: Cancel
         dw C35158                      	; L: Menu
         dw C3515F                      	; L: Party
         dw C35167                      	; L: Change
         dw C3516E                      	; L: Defense
C3507B:  dw C35175                      	; R: Decision
         dw C3517C                      	; R: Cancel
         dw C35183                      	; R: Menu
         dw C3518A                      	; R: Party
         dw C35192                      	; R: Change
         dw C35199                      	; R: Defense
C35087:  dw C351A0                      	; S: Decision
         dw C351A7                      	; S: Cancel
         dw C351AE                      	; S: Menu
         dw C351B5                      	; S: Party
         dw C351BD                      	; S: Change
         dw C351C4                      	; S: Defense

; Positioned text for Button Settings menu
C35093:  dw $78F5 : db |ボタンのせってい[end]|		; Button Settings
C3509E:  dw $79CD : db |けってい[end]|		; A: Decision
C350A5:  dw $79D7 : db |ちゅうし[end]|		; A: Cancel
C350AC:  dw $79E1 : db |メニュー[end]|		; A: Menu
C350B3:  dw $79E9 : db |パーティー[end]|		; A: Party
C350BB:  dw $79F3 : db |チェンジ[end]|		; A: Change
C350C2:  dw $79FD : db |ぼうぎょ[end]|		; A: Defense
C350C9:  dw $7ACD : db |けってい[end]|		; B: Decision
C350D0:  dw $7AD7 : db |ちゅうし[end]|		; B: Cancel
C350D7:  dw $7AE1 : db |メニュー[end]|		; B: Menu
C350DE:  dw $7AE9 : db |パーティー[end]|		; B: Party
C350E6:  dw $7AF3 : db |チェンジ[end]|		; B: Change
C350ED:  dw $7AFD : db |ぼうぎょ[end]|		; B: Defense
C350F4:  dw $7BCD : db |けってい[end]|		; X: Decision
C350FB:  dw $7BD7 : db |ちゅうし[end]|		; X: Cancel
C35102:  dw $7BE1 : db |メニュー[end]|		; X: Menu
C35109:  dw $7BE9 : db |パーティー[end]|		; X: Party
C35111:  dw $7BF3 : db |チェンジ[end]|		; X: Change
C35118:  dw $7BFD : db |ぼうぎょ[end]|		; X: Defense
C3511F:  dw $7CCD : db |けってい[end]|		; Y: Decision
C35126:  dw $7CD7 : db |ちゅうし[end]|		; Y: Cancel
C3512D:  dw $7CE1 : db |メニュー[end]|		; Y: Menu
C35134:  dw $7CE9 : db |パーティー[end]|		; Y: Party
C3513C:  dw $7CF3 : db |チェンジ[end]|		; Y: Change
C35143:  dw $7CFD : db |ぼうぎょ[end]|		; Y: Defense
C3514A:  dw $7DCD : db |けってい[end]|		; L: Decision
C35151:  dw $7DD7 : db |ちゅうし[end]|		; L: Cancel
C35158:  dw $7DE1 : db |メニュー[end]|		; L: Menu
C3515F:  dw $7DE9 : db |パーティー[end]|		; L: Party
C35167:  dw $7DF3 : db |チェンジ[end]|		; L: Change
C3516E:  dw $7DFD : db |ぼうぎょ[end]|		; L: Defense
C35175:  dw $7ECD : db |けってい[end]|		; R: Decision
C3517C:  dw $7ED7 : db |ちゅうし[end]|		; R: Cancel
C35183:  dw $7EE1 : db |メニュー[end]|		; R: Menu
C3518A:  dw $7EE9 : db |パーティー[end]|		; R: Party
C35192:  dw $7EF3 : db |チェンジ[end]|		; R: Change
C35199:  dw $7EFD : db |ぼうぎょ[end]|		; R: Defense
C351A0:  dw $7FCD : db |けってい[end]|		; S: Decision
C351A7:  dw $7FD7 : db |ちゅうし[end]|		; S: Cancel
C351AE:  dw $7FE1 : db |メニュー[end]|		; S: Menu
C351B5:  dw $7FE9 : db |パーティー[end]|		; S: Party
C351BD:  dw $7FF3 : db |チェンジ[end]|		; S: Change
C351C4:  dw $7FFD : db |ぼうぎょ[end]|		; S: Defense
C351CB:  dw $7953 : db |ボタン[end]|		; A: button
C351D1:  dw $7A53 : db |ボタン[end]|		; B: button
C351D7:  dw $7B53 : db |ボタン[end]|		; X: button
C351DD:  dw $7C53 : db |ボタン[end]|		; Y: button
C351E3:  dw $7D53 : db |ボタン[end]|		; L: button
C351E9:  dw $7E53 : db |ボタン[end]|		; R: button
C351EF:  dw $7F57 : db |ボタン[end]|		; S: button
C351F5:  dw $7991 : db "A",$00
C351F9:  dw $7A91 : db "B",$00
C351FD:  dw $7B91 : db "X",$00
C35201:  dw $7C91 : db "Y",$00
C35205:  dw $7D91 : db "L",$00
C35209:  dw $7E91 : db "R",$00
C3520D:  dw $7F91 : db "SEL",$00

; Positioned text, "MP Needed"
C35EE2:  dw $79CD : db |しょうひ MP[end]|

; Pointers to skill names for Skills menu
skillnm: dw C362A0       ; Espers
         dw C362A8       ; Magic
         dw C362AE       ; SwdTech
         dw C362B7       ; Blitz
         dw C362C0       ; Lore
         dw C362C9       ; Rage
         dw C362D0       ; Dance

; Positioned text for Skills menu
C362A0:  dw $78CD : db |げんじゅう[end]|		; Espers
C362A8:  dw $794D : db |まほう[end]|		; Magic
C362AE:  dw $7A4D : db |ひっさつけん[end]|		; SwdTech
C362B7:  dw $7ACD : db |ひっさつわざ[end]|		; Blitz
C362C0:  dw $7B4D : db |おぼえたわざ[end]|		; Lore
C362C9:  dw $7BCD : db |あばれる[end]|		; Rage
C362D0:  dw $7C4D : db |おどり[end]|		; Dance

; Text pointers for Skills menu
C362D6:  dw C36324				; LV
         dw C36329				; HP
         dw C3632E				; MP

; Positioned spaces for blanking diacritics in skill submenu title
C362DC:  dw $80CD : db "      ",$00

; Positioned text for Skills submenus
C362E5:  dw $810D : db "MP…   ",$00
C362EE:  dw $80CD : db |おぼえたわざ[end]|		; Lore
C362F7:  dw $80CD : db |あばれる  [end]|		; Rage
C36300:  dw $80CD : db |おどり   [end]|		; Dance
C36309:  dw $80CD : db |げんじゅう [end]|		; Espers
C36312:  dw $80CD : db |ひっさつわざ[end]|		; Blitz
C3631B:  dw $80CD : db |ひっさつけん[end]|		; SwdTech
C36324:  dw $422D : db "LV",$00
C36329:  dw $42AD : db "HP",$00
C3632E:  dw $432D : db "MP",$00
C36333:  dw $42BB : db "/",$00
C36337:  dw $433B : db "/",$00
C3633B:           : db |がもっています[end]|		; has it!
C36343:  dw $4475 : db |じゅくれんど[end]|		; Skill
C3634C:  dw $4463 : db |おぼえるスピード[end]|		; Learn.Rate
C36357:           : db |レベルアップのときに [end]|	; At level up...

; Text pointers for Status menu
C36A80:  dw C36AD9                              ; Vigor
         dw C36ADF                              ; Stamina
         dw C36AE7                              ; Mag.Pwr
         dw C36AEE                              ; Evade
         dw C36AF6                              ; MBlock‥
         dw C36B03                              ; ‥
         dw C36B07                              ; ‥
         dw C36B0B                              ; ‥
         dw C36B0F                              ; ‥
         dw C36B13                              ; ‥
         dw C36B17                              ; ‥
         dw C36AB2                              ; Status

; Text pointers for Status menu
C36A98:  dw C36ACA                              ; LV
         dw C36ACF                              ; HP
         dw C36AD4                              ; MP

; Text pointers for Status menu
C36A9E:  dw C36ABA                              ; /
         dw C36ABE                              ; /
         dw C36AC2                              ; %
         dw C36AC6                              ; %

; Text pointers for Status menu
C36AA6:  dw C36B1B                              ; Speed
         dw C36B22                              ; Bat.Pwr‥
         dw C36B2F                              ; Defense
         dw C36B36                              ; Mag.Def‥
         dw C36B43                              ; Your Exp:
         dw C36B50                              ; For level up:

; Positioned text for Status menu
C36AB2:  dw $78CD : db |ステータス[end]|		; Status
C36ABA:  dw $3A6B : db "/",$00
C36ABE:  dw $3AAB : db "/",$00
C36AC2:  dw $7F83 : db "%",$00
C36AC6:  dw $8883 : db "%",$00
C36ACA:  dw $3A1D : db "LV",$00
C36ACF:  dw $3A5D : db "HP",$00
C36AD4:  dw $3A9D : db "MP",$00
C36AD9:  dw $7ED1 : db |ちから[end]|		; Vigor
C36ADF:  dw $7FD1 : db |たいりょく[end]|		; Stamina
C36AE7:  dw $8851 : db |まりょく[end]|		; Mag.Pwr
C36AEE:  dw $7F69 : db |かいひりつ[end]|		; Evade
C36AF6:  dw $8869 : db |まほうかいひりつ ‥[end]|		; MBlock‥
C36B03:  dw $7EDD : db |‥[end]|
C36B07:  dw $7F5D : db |‥[end]|
C36B0B:  dw $7FDD : db |‥[end]|
C36B0F:  dw $885D : db |‥[end]|
C36B13:  dw $7EFB : db |‥[end]|
C36B17:  dw $7F7B : db |‥[end]|
C36B1B:  dw $7F11 : db |すばやさ[end]|		; Speed
C36B22:  dw $7E29 : db |こうげきりょく  ‥[end]|		; Bat.Pwr‥
C36B2F:  dw $7EA9 : db |ぼうぎょ[end]|		; Defense
C36B36:  dw $7FA9 : db |まほうぼうぎょ  ‥[end]|		; Mag.Def‥
C36B43:  dw $7C11 : db |げんざいのけいけんち[end]|	; Your Exp:
C36B50:  dw $7D11 : db |つぎのレベルまで あと[end]|	; For level up:

; Text pointers for Lineup menu
C3815D:  dw C38163       ; LV
         dw C38168       ; HP
         dw C3816D       ; MP

; Positioned text for Lineup menu
C38163:  dw $3A6D : db "LV",$00
C38168:  dw $3AED : db "HP",$00
C3816D:  dw $3B6D : db "MP",$00
C38172:  dw $3AFB : db "/",$00
C38176:  dw $3B7B : db "/",$00

; Positioned text for Lineup menu
C3823D:  dw $38CF : db |へんせい[end]|			; "Lineup"
C38229:  dw $38DD : db |パーティーを つ つくってください[end]|		; "Form   group(s).    "
C38244:  dw $38DD : db |パーティーのかずが つありません![end]|		; "You need   group(s)!"
C38258:  dw $38DD : db |だれもいません!         [end]|		; "No one there!       "

; Text for evasion modifiers
C38FDE:  db "  0",$00
         db "+10",$00
         db "+20",$00
         db "+30",$00
         db "+40",$00
         db "+50",$00
         db "-10",$00
         db "-20",$00
         db "-30",$00
         db "-40",$00
         db "-50",$00

; Text for non-evasion stat modifiers
C3900A:  db " 0"
         db "+1"
         db "+2"
         db "+3"
         db "+4"
         db "+5"
         db "+6"
         db "+7"
         db " 0"         ; Unused
         db "-1"
         db "-2"
         db "-3"
         db "-4"
         db "-5"
         db "-6"
         db "-7"

; Text pointers for Item menu
C3949A:  dw C394A7       ; USE
         dw C394AD       ; ARRANGE
         dw C394B4       ; RARE

; Positioned text for Item menu
C394A0:  dw $78CD : db |アイテム[end]|		; Item
C394A7:  dw $78DD : db |つかう[end]|		; USE
C394AD:  dw $78E9 : db |せいとん[end]|		; ARRANGE
C394B4:  dw $78F7 : db |だいじなもの[end]|		; RARE

; Text for gear data menu, " can be used by:"
C394BD:  db |を そうびできるキャラクター[end]|

; Text pointers for gear data menu
C394CC:  dw C394FE       ; Vigor
         dw C39504       ; Stamina
         dw C3950C       ; Mag.Pwr
         dw C39513       ; Evade %
         dw C3951B       ; MBlock%
         dw C39526       ; ‥
         dw C3952A       ; ‥
         dw C3952E       ; ‥
         dw C39532       ; ‥
         dw C39536       ; ‥
         dw C3953A       ; ‥
         dw C3953E       ; ‥
         dw C39542       ; ‥
         dw C39546       ; ‥
C394E8:  dw C3954A       ; Speed
         dw C39551       ; Bat.Pwr
         dw C3955B       ; Defense
         dw C39562       ; Mag.Def
C394F0:  dw C3956C       ; 50% Dmg
         dw C39573       ; Absorb HP
         dw C3957C       ; No Effect
         dw C39582       ; Weak pt

; Positioned text for gear data menu
C394F8:  dw $8643 : db "???",$00
C394FE:  dw $842F : db |ちから[end]|		; Vigor
C39504:  dw $852F : db |たいりょく[end]|		; Stamina
C3950C:  dw $85AF : db |まりょく[end]|		; Mag.Pwr
C39513:  dw $872F : db |かいひりつ[end]|		; Evade %
C3951B:  dw $882F : db |まほうかいひりつ[end]|		; MBlock%
C39526:  dw $843F : db |‥[end]|
C3952A:  dw $84BF : db |‥[end]|
C3952E:  dw $853F : db |‥[end]|
C39532:  dw $85BF : db |‥[end]|
C39536:  dw $863F : db |‥[end]|
C3953A:  dw $86BF : db |‥[end]|
C3953E:  dw $873F : db |‥[end]|
C39542:  dw $87BF : db |‥[end]|
C39546:  dw $883F : db |‥[end]|
C3954A:  dw $846F : db |すばやさ[end]|		; Speed
C39551:  dw $85EF : db |こうげきりょく[end]|		; Bat.Pwr
C3955B:  dw $866F : db |ぼうぎょ[end]|		; Defense
C39562:  dw $876F : db |まほうぼうぎょ[end]|		; Mag.Def
C3956C:  dw $7B4D : db |はんげん[end]|		; 50% Dmg
C39573:  dw $7B69 : db |きゅうしゅう[end]|		; Absorb HP
C3957C:  dw $7C4D : db |むこう[end]|		; No Effect
C39582:  dw $7C69 : db |じゃくてん[end]|		; Weak pt
C3958A:  dw $7B4D : db |こうげき[end]|		; Attack
C39591:  dw $822F : db |ひっさつけん OK[end]|		; SwdTech
C3959D:  dw $82AF : db |まふうけん  OK[end]|		; Runic
C395A9:  dw $832F : db |りょうてもち OK[end]|		; 2-hand

; Positioned text for item usage menu, "Owned:"
C395B5:  dw $79CD : db |もっているかず[end]|

; Positioned spaces for blanking item count in Item menu
C395BF:  dw $7ABF : db "   ",$00

; Text pointers for party gear overview
C3A9F8:  dw C3AA28       ; R-hand
         dw C3AA2D       ; L-hand
         dw C3AA33       ; Head
         dw C3AA39       ; Body
         dw C3AA3F       ; Relic 1
         dw C3AA45       ; Relic 2
C3AA04:  dw C3AA4B       ; R-hand
         dw C3AA50       ; L-hand
         dw C3AA56       ; Head
         dw C3AA5C       ; Body
         dw C3AA62       ; Relic 1
         dw C3AA68       ; Relic 2
C3AA10:  dw C3AA6E       ; R-hand
         dw C3AA73       ; L-hand
         dw C3AA79       ; Head
         dw C3AA7F       ; Body
         dw C3AA85       ; Relic 1
         dw C3AA8B       ; Relic 2
C3AA1C:  dw C3AA91       ; R-hand
         dw C3AA96       ; L-hand
         dw C3AA9C       ; Head
         dw C3AAA2       ; Body
         dw C3AAA8       ; Relic 1
         dw C3AAAE       ; Relic 2

; Positioned party gear overview text for member 1
C3AA28:  dw $394F : db |みぎ[end]|	; R-hand
C3AA2D:  dw $396B : db |ひだり[end]|	; L-hand
C3AA33:  dw $39CF : db |あたま[end]|	; Head
C3AA39:  dw $39EB : db |からだ[end]|	; Body
C3AA3F:  dw $3A4F : db |アク１[end]|	; Relic 1
C3AA45:  dw $3A6B : db |アク２[end]|	; Relic 2

; Positioned party gear overview text for member 2
C3AA4B:  dw $3B4F : db |みぎ[end]|	; R-hand
C3AA50:  dw $3B6B : db |ひだり[end]|	; L-hand
C3AA56:  dw $3BCF : db |あたま[end]|	; Head
C3AA5C:  dw $3BEB : db |からだ[end]|	; Body
C3AA62:  dw $3C4F : db |アク１[end]|	; Relic 1
C3AA68:  dw $3C6B : db |アク２[end]|	; Relic 2

; Positioned party gear overview text for member 3
C3AA6E:  dw $3D4F : db |みぎ[end]|	; R-hand
C3AA73:  dw $3D6B : db |ひだり[end]|	; L-hand
C3AA79:  dw $3DCF : db |あたま[end]|	; Head
C3AA7F:  dw $3DEB : db |からだ[end]|	; Body
C3AA85:  dw $3E4F : db |アク１[end]|	; Relic 1
C3AA8B:  dw $3E6B : db |アク２[end]|	; Relic 2

; Positioned party gear overview text for member 4
C3AA91:  dw $3F4F : db |みぎ[end]|	; R-hand
C3AA96:  dw $3F6B : db |ひだり[end]|	; L-hand
C3AA9C:  dw $3FCF : db |あたま[end]|	; Head
C3AAA2:  dw $3FEB : db |からだ[end]|	; Body
C3AAA8:  dw $404F : db |アク１[end]|	; Relic 1
C3AAAE:  dw $406B : db |アク２[end]|	; Relic 2

; Text pointers for Equip menu
C3AAB4:  dw C3AB1A       ; EQUIP
         dw C3AB20       ; OPTIMUM
         dw C3AB28       ; RMOVE
         dw C3AB2E       ; EMPTY
C3AABC:  dw C3AAD5       ; Head
         dw C3AADB       ; Body

; Text pointers for Relic menu
C3AAC0:  dw C3AB38       ; EQUIP
         dw C3AB3E       ; REMOVE
C3AAC4:  dw C3AAE1       ; Relic
         dw C3AAE9       ; Relic

; Positioned text for Equip and Relic menus
C3AAC8:  dw $79CD : db |みぎて[end]|	; R-hand
C3AACE:  dw $7A4D : db |ひだりて[end]|	; L-hand
C3AAD5:  dw $7ACD : db |あたま[end]|	; Head
C3AADB:  dw $7B4D : db |からだ[end]|	; Body
C3AAE1:  dw $7ACD : db |アクセサリ[end]|	; Relic
C3AAE9:  dw $7B4D : db |アクセサリ[end]|	; Relic

; Positioned text for title in Equip and Relic menus
C3AB0E:  dw $78FD : db |そうび[end]|	; EQUIP
C3AB14:  dw $78FD : db |はずす[end]|	; REMOVE

; Positioned text for options in Equip menu
C3AB1A:  dw $78D1 : db |そうび[end]	|	; EQUIP
C3AB20:  dw $78DB : db |さいきょう[end]|	; OPTIMUM
C3AB28:  dw $78E9 : db |はずす[end]|	; RMOVE
C3AB2E:  dw $78F5 : db |すべてはずす [end]|	; EMPTY

; Positioned text for options in Relic menu
C3AB38:  dw $78D1 : db |そうび[end]|	; EQUIP
C3AB3E:  dw $78DB : db |はずす[end]|	; REMOVE

; Text pointers for Equip and Relic menus
C3AB44:  dw C3AB68					; Vigor
         dw C3AB6E					; Stamina
         dw C3AB76					; Mag.Pwr
         dw C3AB7D					; Evade %
         dw C3AB85					; MBlock%
         dw C3AB90					; →
         dw C3AB94					; →
         dw C3AB98					; →
         dw C3AB9C					; →
         dw C3ABA0					; →
         dw C3ABA4					; →
         dw C3ABA8					; →
         dw C3ABAC					; →
         dw C3ABB0					; →
C3AB60:  dw C3ABB4					; Speed
         dw C3ABBB					; Bat.Pwr
         dw C3ABC5					; Defense
         dw C3ABCC					; Mag.Def

; Positioned text for Equip and Relic menus
C3AB68:  dw $7CA7 : db |ちから[end]|			; Vigor
C3AB6E:  dw $7DA7 : db |たいりょく[end]|			; Stamina
C3AB76:  dw $7E27 : db |まりょく[end]|			; Mag.Pwr
C3AB7D:  dw $7FA7 : db |かいひりつ[end]|			; Evade %
C3AB85:  dw $80A7 : db |まほうかいひりつ[end]|			; MBlock%
C3AB90:  dw $7CBD : db |→[end]|
C3AB94:  dw $7D3D : db |→[end]|
C3AB98:  dw $7DBD : db |→[end]|
C3AB9C:  dw $7E3D : db |→[end]|
C3ABA0:  dw $7F3D : db |→[end]|
C3ABA4:  dw $7FBD : db |→[end]|
C3ABA8:  dw $7EBD : db |→[end]|
C3ABAC:  dw $803D : db |→[end]|
C3ABB0:  dw $80BD : db |→[end]|
C3ABB4:  dw $7CE7 : db |すばやさ[end]|			; Speed
C3ABBB:  dw $7E67 : db |こうげきりょく[end]|			; Bat.Pwr
C3ABC5:  dw $7EE7 : db |ぼうぎょ[end]|			; Defense
C3ABCC:  dw $7FE7 : db |まほうぼうぎょ[end]|			; Mag.Def
C3ABD6:  dw $79F3 : db "      ",$00  			; Blank effect A
C3ABDF:  dw $7A73 : db "      ",$00  			; Blank effect B
C3ABE8:  dw $7A6F : db |じゅうそうび[end]|			; Heavy gear
C3ABF1:  dw $79EF : db |にとうりゅう[end]|			; Dual wield
C3ABFA:  dw $7A6F : db |りょうてもち[end]|			; Two-handed
C3AC03:  dw $78E1 : db |「すべてはずす」[end]|			; Empty
C3AC0E:  dw $78E1 : db |「さいきょうそうび」[end]|			; Optimum
C3AC1B:  dw $7961 : db |「すべてはずす」[end]|			; Empty
C3AC26:  dw $7961 : db |「さいきょうそうび」[end]|			; Optimum
C3AC33:  dw $79CF : db |そうびにかかわるアクセサリーが へんこうされました[end]|	; Equipment changed.

; Text pointers for final battle lineup
C3B5F4:  dw C3B5FA       ; End
         dw C3B600       ; Reset
         dw C3B608       ; Determine order

; Positioned text for final battle lineup
C3B5FA:  dw $3FD1 : db |おわり[end]|			; End
C3B600:  dw $3951 : db |やりなおし[end]|			; Reset
C3B608:  dw $38DD : db |じゅんばんを きめてください[end]|		; Determine order

; Positioned text for Colosseum
C3B709:  dw $78CD : db |コロシアム[end]|			; Colosseum
C3B711:  dw $78DB : db |アイテムを１つ えらんでください[end]|		; Select an Item

; Positioned spaces for blanking challenger's name
C3BD73:  dw $7C35 : db "      ",$00

; Positioned Colosseum text, "Select the challenger"
C3BD7C:  dw $7D19 : db |ちょうせんしゃをきめてください[end]|

; Positioned Colosseum text, "????????"
C3BD8E:  dw $7911 : db "????????", $00

; Positioned text for SwdTech naming menu
C3C244:  dw $390D : db "«¤±±±±±±±»",$00
C3C251:  dw $388F : db |ひっさつけん[end]|			; SwdTech

; Positioned text for shop menu
C3D257:  dw $78CF : db |ぶきや[end]|			; Weapon
C3D25D:  dw $78CF : db |ぼうぐや[end]|			; Armor
C3D264:  dw $78CF : db |どうぐや[end]|			; Item
C3D26B:  dw $78CD : db |アクセサリーや[end]|			; Relics
C3D275:  dw $78CD : db |ぎょうしょう[end]|			; Vendor
C3D27E:  dw $79CF : db |かう  うる  でる[end]|			; BUY  SELL  EXIT
C3D28B:  dw $7A01 : db |ギル[end]|			; GP (owned)
C3D290:  dw $7AEB : db |ギル[end]|			; GP (trade)
C3D295:  dw $7A73 : db |もっているかず[end]|			; Owned:
C3D29F:  dw $7B73 : db |そうびしているかず[end]|			; Equipped:
C3D2AB:  dw $7B55 : db |こうげきりょく ‥[end]|			; Bat Pwr
C3D2B7:  dw $7B55 : db |ぼうぎょ[end]|			; Defense
C3D2BE:  dw $7BA5 : db |‥[end]|				; ‥
C3D2C2:  dw $78DF : db |「いらっしゃい!どんなごようけんで?」[end]|		; Hi! Can I help you?
C3D2D8:  dw $78DF : db |「なにが ほしいんだいっ!?」    [end]|	; Help yourself!
C3D2EE:  dw $78DF : db |「いくつ ほしいんだいっ!?」[end]|		; How many?
C3D300:  dw $78DF : db |「なにを うりたいんだい?」     [end]| 	; Whatcha got?
C3D316:  dw $78DF : db |「いくつ うりたいんだい?」[end]|		; How many?
C3D327:  dw $78DF : db |「まいど どーも!」         [end]|	; "Bye!          "
C3D33D:  dw $78DF : db |「‥‥おかねが たりないようだね」[end]|		; You need more GP!
C3D351:  dw $78DF : db |「もう もてないよ」     [end]|		; "Too many!       "
C3D363:  dw $78DF : db |「１つあれば じゅうぶんだよ」[end]|		; "One's plenty! "

; =========================[ New general functions ]===========================

; Set data bank register to 7E
db7e:    LDA #$7E        ; Bank: 7E
         PHA             ; Put on stack
         PLB             ; Set DB to 7E
         TDC             ; Clear A
         RTS

; Set WRAM address to 7E/9D89
wm9D89:  PHX             ; Save X
         LDX #$9D89      ; 7E/9D89
         BRA wmplx       ; Set WRAM LBs

; Set WRAM address to 7E/9E8B
wm9E8B:  PHX             ; Save X
         LDX #$9E8B      ; 7E/9E8B
wmplx:   STX $2181       ; Set WRAM LBs
         PLX             ; Restore X
         RTS

; Multiply A by 16, 32, or 64
x64:     REP #$20        ; 16-bit A
         ASL A           ; x64
x32r:    REP #$20        ; 16-bit A
x32:     ASL A           ; x32
x16:     ASL A           ; x16
         ASL A           ; x8
         ASL A           ; x4
         ASL A           ; x2
         RTS

; Multiply B by A
mul8:    PHP             ; Save PS
         REP #$20        ; 16-bit A
         STA $004202     ; Set factors
         NOP             ; Waste 2 cycles
         NOP             ; Waste 2 cycles
         LDA $004216     ; Product
         PLP             ; Restore PS
         CLC             ; Prepare ADC
         RTS

; Multiply 8-bit A by Y
mul16:   PHA             ; Save multiplicand
.loop    LDA $004212     ; PPU status
         ASL A           ; H-Blank?
         BPL .loop       ; Loop if not
         PLA             ; Multiplicand
         STA $00211C     ; Set matrix B
         PHY             ; Push multiplier
         PLA             ; Pull low byte
         STA $00211B     ; Set matrix A LB
         PLA             ; Pull high byte
         STA $00211B     ; Set matrix A HB
         LDX $2134       ; Product LBs
         LDA $2136       ; Product HB
         RTS             ; ^ Add 00 if needed

; Clear VWF graphics buffer
clr_vwf: LDX #$A271      ; 7E/A271

; Clear a block of RAM
clr_ram: PHB             ; Save DB
         TDC             ; Zero A
         PHA             ; Put on stack
         PLB             ; Set DB to 0
         STY $4305       ; Set data size
         STX $2181       ; Set WRAM LBs
         LDA #$7E        ; Bank: 7E
         STA $2183       ; Set WRAM HB
         LDX #C3091A     ; C3/0895
         STX $4302       ; Set src LBs
         LDA #$C3        ; Bank: C3
         STA $4304       ; Set src HB
         LDA #$80        ; $2180
         STA $4301       ; To WRAM
         LDA #$08        ; 1Rx1B to PPU
         STA $4300       ; Src = Fixed
         LDA #$01        ; Channel: 0
         STA $420B       ; Move data
         PLB             ; Restore DB
         RTS

; Clear BG2 tilemaps
bg2c_cl: JSR C371C6      ; Clear BG2 map C
bg2b_cl: JSR C371C1      ; Clear BG2 map B
         JMP C371BC      ; Clear BG2 map A

; Clear BG3 tilemaps
bg3d_cl: JSR C371DF      ; Clear BG3 map D
bg3c_cl: JSR C371DA      ; Clear BG3 map C
bg3b_cl: JSR C371D5      ; Clear BG3 map B
         JMP C371D0      ; Clear BG3 map A

; Shift BG1 write row down by 4 rows
e6add4:  JSR e6add2      ; BG1 WR row +2

; Shift BG1 write row down by 2 rows
e6add2:  LDA $E6         ; BG1 write row
         INC A           ; Go 1 row down
         INC A           ; Go 1 row down
         AND #$1F        ; Stay in limits
         STA $E6         ; Save changes
         RTS

; Add two-digit number to string
add2n:   LDA $F8         ; Tens digit
         STA $2180       ; Add to string
         LDA $F9         ; Ones digit
         STA $2180       ; Add to string
         RTS

; Draw Y spaces
spacedr: JSR wm9E8B      ; WRAM: 7E/9E8B
         JSR spaces      ; Build string
         JMP C387B_      ; Draw string

; Add Y spaces to string, terminate string
spaces:  SEP #$20        ; 8-bit A
         LDA #$FF        ; Space char
.loop    STA $2180       ; Add to string
         DEY             ; One less left
         BNE .loop       ; Loop till last
         RTS

; Load fixed-size string from table (variant of C38BF2)
fw_txt:  JSR wm9E8B      ; WRAM: 7E/9E8B
         STY $FD         ; Set src LBs
         STA $FF         ; Set src HB
         TXA             ; String size
         JSR mul8        ; Number x size
         TAY             ; Index product
.loop    LDA [$FD],Y     ; Letter
         STA $2180       ; Add to string
         INY             ; Point to next
         DEX             ; One less left
         BNE .loop       ; Loop till last
         RTS

; Set sprite's position
objpos:  PHY             ; Push coords
         PLA             ; X position
         STA $7E33CA,X   ; Set sprite's
         PLA             ; Y position
         STA $7E344A,X   ; Set sprite's
         RTS

; Set animation table pointer to C3/YYYY
anm_c3:  SEP #$20        ; 8-bit A
         LDA #$C3        ; Bank: C3

; Set animation table pointer to AA/YYYY
anm_st:  STA $7E35CA,X   ; Set ptr HB
         REP #$20        ; 16-bit A
         TYA             ; Anim table ptr
         STA $7E32C9,X   ; Set sprite's
         SEP #$20        ; 8-bit A
         RTS

; Load pointer to portrait's graphics
faceptr: TDC             ; Clear A
         SEP #$20        ; 8-bit A
         TYX             ; Actor's address
         LDA $14,X       ; Status
         AND #$20        ; Imp?
         BEQ .locke      ; Branch if not
         LDA #$0F        ; Use Imp image
         BRA .load       ; Ignore actor
.locke   LDA $00,X       ; Actor
         CMP #$01        ; Locke?
         BEQ .load       ; Branch if so
         LDA $01,X       ; Graphics set
.load    REP #$20        ; 16-bit A
         ASL A           ; Double it
         TAX             ; Index it
         LDA.L C376AF,X  ; GFX pointer
         RTS

; Get item class
itm_cl1: JSR C38AA2      ; Compute index
itm_cl2: LDX $4216       ; Load it
         TDC             ; Clear A
         LDA $D85000,X   ; Properties
         AND #$07        ; Get class
         RTS

; Get entry in list of available gear
ldgear1: TDC             ; Clear A
         LDA $4B         ; Gear list slot
ldgear2: TAX             ; Index it
ldgear3: TDC             ; Clear A
         LDA $7E9D8A,X   ; Inventory slot
         TAX             ; Index it
         LDA $1869,X     ; Item in slot
         RTS

; Check if processing Gogo
gogo1:   JSR C32D9E      ; Actor's address
gogo2:   LDA $0000,Y     ; Actor
         CMP #$0C        ; Gogo?
         RTS

; Save color in CGRAM
cgram:   SEP #$20        ; 8-bit A
         STA $2122       ; Put LB in CGRAM
         XBA             ; Switch to HB
         STA $2122       ; Put HB in CGRAM
         INX             ; Color index +1
         INX             ; Color index +1
         RTS

; Restore cursor position in previous menu
oldcur:  LDY $8E         ; Old cursor loc
         STY $4F         ; Set as current
         TYA             ; Old cursor column
         STA $4D         ; Set onscreen col
         LDA $90         ; Old scroll pos
;        STA $4A         ; Set as current
         JMP C30E89      ; Def cursor row

; Set up BG1 H-Shift HDMA
bg1h_:   LDA #$7E        ; Bank: 7E
bg1h:    STA $4364       ; Set CH6 src HB
         STY $4362       ; Set CH6 src LBs
         LDA #$02        ; 1Rx2B to PPU
         STA $4360       ; Set CH6 mode
         LDA #$0D        ; $210D
         STA $4361       ; To BG1 H-Scroll
         LDA #$40        ; Channel: 6
         BRA tsb43       ; Queue HDMA-6

; Set up BG1 V-Shift HDMA
bg1v_:   LDA #$7E        ; Bank: 7E
bg1v:    STA $4374       ; Set CH7 src HB
         STY $4372       ; Set CH7 src LBs
         LDA #$02        ; 1Rx2B to PPU
         STA $4370       ; Set CH7 mode
         LDA #$0E        ; $210E
         STA $4371       ; To BG1 V-Scroll
         LDA #$80        ; Channel: 7
         BRA tsb43       ; Queue HDMA-7

; Set up BG3 V-Shift HDMA
bg3v_:   LDA #$C3        ; Bank: C3
bg3v:    STA $4354       ; Set CH5 src HB
         STY $4352       ; Set CH5 src LBs
         LDA #$02        ; 1Rx2B to PPU
         STA $4350       ; Set CH5 mode
         LDA #$12        ; $2112
         STA $4351       ; To BG3 V-Scroll
         LDA #$20        ; Channel: 5
tsb43:   TSB $43         ; Queue HDMA-5
         RTS

; Draw and upload multiple menu windows
boxes_:  JSR boxes       ; Draw boxes
         JMP C30EBD      ; Upload BG2 A+B

; Draw multiple menu windows
boxes:   PHX             ; Save index
         JSR C303C4      ; Draw a window
         PLX             ; Window index
         INX             ; Index +1
         INX             ; Index +1
         INX             ; Index +1
         INX             ; Index +1
         LDA.L C30000,X  ; More windows?
         BNE boxes       ; Loop if so
         RTS

; =============================================================================

; Warn on bank overflow
warnpc $C40000

; Blank rest of bank
padbyte $FF : pad $C40000
